Skip to content

Commit fb19560

Browse files
committed
std::env docs
1 parent 386b0b9 commit fb19560

File tree

1 file changed

+35
-18
lines changed

1 file changed

+35
-18
lines changed

src/libstd/env.rs

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
//! This module contains functions to inspect various aspects such as
1414
//! environment variables, process arguments, the current directory, and various
1515
//! other important directories.
16+
//!
17+
//! There are several functions and structs in this module that have a
18+
//! counterpart ending in `os`. Those ending in `os` will return an [`OsString`]
19+
//! and those without will be returning a [`String`].
20+
//!
21+
//! [`OsString`]: ../../std/ffi/struct.OsString.html
22+
//! [`String`]: ../string/struct.String.html
1623
1724
#![stable(feature = "env", since = "1.0.0")]
1825

@@ -71,15 +78,17 @@ pub fn set_current_dir<P: AsRef<Path>>(p: P) -> io::Result<()> {
7178

7279
/// An iterator over a snapshot of the environment variables of this process.
7380
///
74-
/// This structure is created through the [`std::env::vars`] function.
81+
/// This structure is created by the [`std::env::vars`] function. See its
82+
/// documentation for more.
7583
///
7684
/// [`std::env::vars`]: fn.vars.html
7785
#[stable(feature = "env", since = "1.0.0")]
7886
pub struct Vars { inner: VarsOs }
7987

8088
/// An iterator over a snapshot of the environment variables of this process.
8189
///
82-
/// This structure is created through the [`std::env::vars_os`] function.
90+
/// This structure is created by the [`std::env::vars_os`] function. See
91+
/// its documentation for more.
8392
///
8493
/// [`std::env::vars_os`]: fn.vars_os.html
8594
#[stable(feature = "env", since = "1.0.0")]
@@ -173,12 +182,10 @@ impl fmt::Debug for VarsOs {
173182

174183
/// Fetches the environment variable `key` from the current process.
175184
///
176-
/// The returned result is [`Ok(s)`] if the environment variable is present and is
177-
/// valid unicode. If the environment variable is not present, or it is not
178-
/// valid unicode, then [`Err`] will be returned.
185+
/// # Errors
179186
///
180-
/// [`Ok(s)`]: ../result/enum.Result.html#variant.Ok
181-
/// [`Err`]: ../result/enum.Result.html#variant.Err
187+
/// * Environment variable is not present
188+
/// * Environment variable is not valid unicode
182189
///
183190
/// # Examples
184191
///
@@ -230,7 +237,8 @@ fn _var_os(key: &OsStr) -> Option<OsString> {
230237
})
231238
}
232239

233-
/// Possible errors from the [`env::var`] function.
240+
/// The error type for operations interacting with environment variables.
241+
/// Possibly returned from the [`env::var`] function.
234242
///
235243
/// [`env::var`]: fn.var.html
236244
#[derive(Debug, PartialEq, Eq, Clone)]
@@ -353,10 +361,13 @@ fn _remove_var(k: &OsStr) {
353361
})
354362
}
355363

356-
/// An iterator over `PathBuf` instances for parsing an environment variable
357-
/// according to platform-specific conventions.
364+
/// An iterator that splits an environment variable into paths according to
365+
/// platform-specific conventions.
358366
///
359-
/// This structure is returned from `std::env::split_paths`.
367+
/// This structure is created by the [`std::env::split_paths`] function See its
368+
/// documentation for more.
369+
///
370+
/// [`std::env::split_paths`]: fn.split_paths.html
360371
#[stable(feature = "env", since = "1.0.0")]
361372
pub struct SplitPaths<'a> { inner: os_imp::SplitPaths<'a> }
362373

@@ -399,8 +410,10 @@ impl<'a> fmt::Debug for SplitPaths<'a> {
399410
}
400411
}
401412

402-
/// Error type returned from `std::env::join_paths` when paths fail to be
403-
/// joined.
413+
/// The error type for operations on the `PATH` variable. Possibly returned from
414+
/// the [`env::join_paths`] function.
415+
///
416+
/// [`env::join_paths`]: fn.join_paths.html
404417
#[derive(Debug)]
405418
#[stable(feature = "env", since = "1.0.0")]
406419
pub struct JoinPathsError {
@@ -410,15 +423,15 @@ pub struct JoinPathsError {
410423
/// Joins a collection of [`Path`]s appropriately for the `PATH`
411424
/// environment variable.
412425
///
413-
/// Returns an [`OsString`] on success.
426+
/// # Errors
414427
///
415-
/// Returns an [`Err`][err] (containing an error message) if one of the input
428+
/// Returns an [`Err`] (containing an error message) if one of the input
416429
/// [`Path`]s contains an invalid character for constructing the `PATH`
417430
/// variable (a double quote on Windows or a colon on Unix).
418431
///
419432
/// [`Path`]: ../../std/path/struct.Path.html
420433
/// [`OsString`]: ../../std/ffi/struct.OsString.html
421-
/// [err]: ../../std/result/enum.Result.html#variant.Err
434+
/// [`Err`]: ../../std/result/enum.Result.html#variant.Err
422435
///
423436
/// # Examples
424437
///
@@ -490,12 +503,16 @@ pub fn home_dir() -> Option<PathBuf> {
490503

491504
/// Returns the path of a temporary directory.
492505
///
493-
/// On Unix, returns the value of the `TMPDIR` environment variable if it is
506+
/// # Unix
507+
///
508+
/// Returns the value of the `TMPDIR` environment variable if it is
494509
/// set, otherwise for non-Android it returns `/tmp`. If Android, since there
495510
/// is no global temporary folder (it is usually allocated per-app), it returns
496511
/// `/data/local/tmp`.
497512
///
498-
/// On Windows, returns the value of, in order, the `TMP`, `TEMP`,
513+
/// # Windows
514+
///
515+
/// Returns the value of, in order, the `TMP`, `TEMP`,
499516
/// `USERPROFILE` environment variable if any are set and not the empty
500517
/// string. Otherwise, `temp_dir` returns the path of the Windows directory.
501518
/// This behavior is identical to that of [`GetTempPath`][msdn], which this

0 commit comments

Comments
 (0)