Skip to content

Commit

Permalink
doc: std::env::var: Returns None for names with '=' or NUL byte
Browse files Browse the repository at this point in the history
The documentation incorrectly stated that std::env::var could return
an error for variable names containing '=' or the NUL byte. Copy the
correct documentation from var_os.

var_os was fixed in Commit 8a7a665, Pull Request rust-lang#109894, which
closed Issue rust-lang#109893.

This documentation was incorrectly added in commit f2c0f29, which
replaced a panic in var_os by returning None, but documented the
change as "May error if ...".

Reference the specific error values and link to them.
  • Loading branch information
evanj committed Aug 9, 2024
1 parent f74940d commit 9668691
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions std/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,16 @@ impl fmt::Debug for VarsOs {
///
/// # Errors
///
/// This function will return an error if the environment variable isn't set.
/// This function returns [`VarError::NotPresent`] if the environment variable
/// isn't set.
///
/// This function may return an error if the environment variable's name contains
/// the equal sign character (`=`) or the NUL character.
/// This function may return [`VarError::NotPresent`] if the
/// environment variable's name contains the equal sign character (`=`) or the
/// NUL character.
///
/// This function will return an error if the environment variable's value is
/// not valid Unicode. If this is not desired, consider using [`var_os`].
/// This function will return [`VarError::NotUnicode`] if the environment
/// variable's value is not valid Unicode. If this is not desired, consider
/// using [`var_os`].
///
/// # Examples
///
Expand Down

0 comments on commit 9668691

Please sign in to comment.