Skip to content
forked from rust-lang/rust
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ce29159

Browse files
committedMay 21, 2024
Simplify environment variable examples
I’ve found myself visiting the documentation for `std::env::vars` every few months, and every time I do, it is because I want to quickly get a snippet to print out all environment variables :-) So I think it could be nice to simplify the examples a little to make them self-contained. It is of course a style question if one should import a module a not, but I personally don’t import modules used just once in a code snippet.
1 parent 8dd9e07 commit ce29159

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed
 

‎std/src/env.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,8 @@ pub struct VarsOs {
120120
/// # Examples
121121
///
122122
/// ```
123-
/// use std::env;
124-
///
125-
/// // We will iterate through the references to the element returned by
126-
/// // env::vars();
127-
/// for (key, value) in env::vars() {
123+
/// // Print all environment variables.
124+
/// for (key, value) in std::env::vars() {
128125
/// println!("{key}: {value}");
129126
/// }
130127
/// ```
@@ -150,11 +147,8 @@ pub fn vars() -> Vars {
150147
/// # Examples
151148
///
152149
/// ```
153-
/// use std::env;
154-
///
155-
/// // We will iterate through the references to the element returned by
156-
/// // env::vars_os();
157-
/// for (key, value) in env::vars_os() {
150+
/// // Print all environment variables.
151+
/// for (key, value) in std::env::vars_os() {
158152
/// println!("{key:?}: {value:?}");
159153
/// }
160154
/// ```

0 commit comments

Comments
 (0)
Failed to load comments.