From aca631fb9b444fbce3e52a092289518363c0af50 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 8 Jan 2024 13:14:30 -0500 Subject: [PATCH 1/2] Increase visibility of `join_path` and `split_paths` Add some crosslinking among `std::env` pages. Also add aliases to help anyone searching for `PATH`. --- library/std/src/env.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/library/std/src/env.rs b/library/std/src/env.rs index 30ac0512348ca..e662b26316b75 100644 --- a/library/std/src/env.rs +++ b/library/std/src/env.rs @@ -258,6 +258,9 @@ fn _var(key: &OsStr) -> Result { /// None => println!("{key} is not defined in the environment.") /// } /// ``` +/// +/// If expecting a delimited variable (such as `PATH`), [`split_paths`] +/// can be used to separate items. #[must_use] #[stable(feature = "env", since = "1.0.0")] pub fn var_os>(key: K) -> Option { @@ -441,6 +444,16 @@ pub struct SplitPaths<'a> { /// Returns an iterator over the paths contained in `unparsed`. The iterator /// element type is [`PathBuf`]. /// +/// On most Unix platforms, the separator is `:` and on Windows it is `;`. This +/// also performs unquoting on Windows. +/// +/// [`join_paths`] can be used to recombine elements. +/// +/// # Panics +/// +/// This will panic on systems where theere is no delimited `PATH` variable, +/// such as UEFI. +/// /// # Examples /// /// ``` @@ -456,6 +469,7 @@ pub struct SplitPaths<'a> { /// None => println!("{key} is not defined in the environment.") /// } /// ``` +#[doc(alias = "PATH")] #[stable(feature = "env", since = "1.0.0")] pub fn split_paths + ?Sized>(unparsed: &T) -> SplitPaths<'_> { SplitPaths { inner: os_imp::split_paths(unparsed.as_ref()) } @@ -496,7 +510,8 @@ pub struct JoinPathsError { /// /// Returns an [`Err`] (containing an error message) if one of the input /// [`Path`]s contains an invalid character for constructing the `PATH` -/// variable (a double quote on Windows or a colon on Unix). +/// variable (a double quote on Windows or a colon on Unix), or if the system +/// does not have a `PATH`-like variable (e.g. UEFI or WASI). /// /// # Examples /// @@ -550,6 +565,7 @@ pub struct JoinPathsError { /// ``` /// /// [`env::split_paths()`]: split_paths +#[doc(alias = "PATH")] #[stable(feature = "env", since = "1.0.0")] pub fn join_paths(paths: I) -> Result where From 0de367748c41af843b4989d4039269ac2092c903 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Sat, 10 Feb 2024 18:59:47 -0800 Subject: [PATCH 2/2] Fix typo Co-authored-by: Benjamin Peter <145429680+benjamin-nw@users.noreply.github.com> --- library/std/src/env.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/env.rs b/library/std/src/env.rs index e662b26316b75..a46ddfd949170 100644 --- a/library/std/src/env.rs +++ b/library/std/src/env.rs @@ -451,7 +451,7 @@ pub struct SplitPaths<'a> { /// /// # Panics /// -/// This will panic on systems where theere is no delimited `PATH` variable, +/// This will panic on systems where there is no delimited `PATH` variable, /// such as UEFI. /// /// # Examples