Skip to content

Commit 58bbe1d

Browse files
committed
Add a couple doc additional examples for env::join_paths.
1 parent 93abc2f commit 58bbe1d

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/libstd/env.rs

+29
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,35 @@ pub struct JoinPathsError {
438438
///
439439
/// # Examples
440440
///
441+
/// Joining paths on a Unix-like platform:
442+
///
443+
/// ```
444+
/// # if cfg!(unix) {
445+
/// use std::env;
446+
/// use std::ffi::OsString;
447+
/// use std::path::Path;
448+
///
449+
/// let paths = [Path::new("/bin"), Path::new("/usr/bin")];
450+
/// let path_os_string = env::join_paths(paths.iter()).unwrap();
451+
/// assert_eq!(path_os_string, OsString::from("/bin:/usr/bin"));
452+
/// # }
453+
/// ```
454+
///
455+
/// Joining a path containing a colon on a Unix-like platform results in an error:
456+
///
457+
/// ```
458+
/// # if cfg!(unix) {
459+
/// use std::env;
460+
/// use std::path::Path;
461+
///
462+
/// let paths = [Path::new("/bin"), Path::new("/usr/bi:n")];
463+
/// assert!(env::join_paths(paths.iter()).is_err());
464+
/// # }
465+
/// ```
466+
///
467+
/// Using `env::join_paths` with `env::spit_paths` to append an item to the `PATH` environment
468+
/// variable:
469+
///
441470
/// ```
442471
/// use std::env;
443472
/// use std::path::PathBuf;

0 commit comments

Comments
 (0)