about summary refs log tree commit diff
path: root/library/std/src/env.rs
diff options
context:
space:
mode:
authorMartin Geisler <mgeisler@google.com>2024-05-17 11:54:21 +0200
committerMartin Geisler <mgeisler@google.com>2024-05-21 15:36:19 +0200
commit62e29fe25b039b89ad76a6b9a94f8085eee934d9 (patch)
treeddff1172a25ce2d80e22a64c4df75a1810433002 /library/std/src/env.rs
parent1189851eebdf6b69b164bbb7bf9df91188ae03aa (diff)
downloadrust-62e29fe25b039b89ad76a6b9a94f8085eee934d9.tar.gz
rust-62e29fe25b039b89ad76a6b9a94f8085eee934d9.zip
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.
Diffstat (limited to 'library/std/src/env.rs')
-rw-r--r--library/std/src/env.rs14
1 files changed, 4 insertions, 10 deletions
diff --git a/library/std/src/env.rs b/library/std/src/env.rs
index 6f8ac17f12c..b3428fb23ba 100644
--- a/library/std/src/env.rs
+++ b/library/std/src/env.rs
@@ -120,11 +120,8 @@ pub struct VarsOs {
 /// # Examples
 ///
 /// ```
-/// use std::env;
-///
-/// // We will iterate through the references to the element returned by
-/// // env::vars();
-/// for (key, value) in env::vars() {
+/// // Print all environment variables.
+/// for (key, value) in std::env::vars() {
 ///     println!("{key}: {value}");
 /// }
 /// ```
@@ -150,11 +147,8 @@ pub fn vars() -> Vars {
 /// # Examples
 ///
 /// ```
-/// use std::env;
-///
-/// // We will iterate through the references to the element returned by
-/// // env::vars_os();
-/// for (key, value) in env::vars_os() {
+/// // Print all environment variables.
+/// for (key, value) in std::env::vars_os() {
 ///     println!("{key:?}: {value:?}");
 /// }
 /// ```