Skip to content
/ rust Public
forked from rust-lang/rust

Commit 06d4878

Browse files
authored
Rollup merge of rust-lang#119748 - tgross35:suggest-path-split, r=Amanieu
Increase visibility of `join_path` and `split_paths` Add some crosslinking among `std::env` pages to make it easier to discover `join_paths` and `split_paths`. Also add aliases to help anyone searching for `PATH`.
2 parents d3d145e + 0de3677 commit 06d4878

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

library/std/src/env.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ fn _var(key: &OsStr) -> Result<String, VarError> {
258258
/// None => println!("{key} is not defined in the environment.")
259259
/// }
260260
/// ```
261+
///
262+
/// If expecting a delimited variable (such as `PATH`), [`split_paths`]
263+
/// can be used to separate items.
261264
#[must_use]
262265
#[stable(feature = "env", since = "1.0.0")]
263266
pub fn var_os<K: AsRef<OsStr>>(key: K) -> Option<OsString> {
@@ -441,6 +444,16 @@ pub struct SplitPaths<'a> {
441444
/// Returns an iterator over the paths contained in `unparsed`. The iterator
442445
/// element type is [`PathBuf`].
443446
///
447+
/// On most Unix platforms, the separator is `:` and on Windows it is `;`. This
448+
/// also performs unquoting on Windows.
449+
///
450+
/// [`join_paths`] can be used to recombine elements.
451+
///
452+
/// # Panics
453+
///
454+
/// This will panic on systems where there is no delimited `PATH` variable,
455+
/// such as UEFI.
456+
///
444457
/// # Examples
445458
///
446459
/// ```
@@ -456,6 +469,7 @@ pub struct SplitPaths<'a> {
456469
/// None => println!("{key} is not defined in the environment.")
457470
/// }
458471
/// ```
472+
#[doc(alias = "PATH")]
459473
#[stable(feature = "env", since = "1.0.0")]
460474
pub fn split_paths<T: AsRef<OsStr> + ?Sized>(unparsed: &T) -> SplitPaths<'_> {
461475
SplitPaths { inner: os_imp::split_paths(unparsed.as_ref()) }
@@ -496,7 +510,8 @@ pub struct JoinPathsError {
496510
///
497511
/// Returns an [`Err`] (containing an error message) if one of the input
498512
/// [`Path`]s contains an invalid character for constructing the `PATH`
499-
/// variable (a double quote on Windows or a colon on Unix).
513+
/// variable (a double quote on Windows or a colon on Unix), or if the system
514+
/// does not have a `PATH`-like variable (e.g. UEFI or WASI).
500515
///
501516
/// # Examples
502517
///
@@ -550,6 +565,7 @@ pub struct JoinPathsError {
550565
/// ```
551566
///
552567
/// [`env::split_paths()`]: split_paths
568+
#[doc(alias = "PATH")]
553569
#[stable(feature = "env", since = "1.0.0")]
554570
pub fn join_paths<I, T>(paths: I) -> Result<OsString, JoinPathsError>
555571
where

0 commit comments

Comments
 (0)