]> git.lizzy.rs Git - rust.git/commitdiff
Add a couple doc additional examples for `env::join_paths`.
authorCorey Farwell <coreyf@rwell.org>
Mon, 19 Jun 2017 02:21:17 +0000 (19:21 -0700)
committerCorey Farwell <coreyf@rwell.org>
Tue, 20 Jun 2017 17:49:42 +0000 (13:49 -0400)
src/libstd/env.rs

index 889ba81e77812dd9c2a268951cad1c83b0394a20..770bca7524c2411147b5cc50087238a5cfdc5964 100644 (file)
@@ -438,6 +438,35 @@ pub struct JoinPathsError {
 ///
 /// # Examples
 ///
+/// Joining paths on a Unix-like platform:
+///
+/// ```
+/// # if cfg!(unix) {
+/// use std::env;
+/// use std::ffi::OsString;
+/// use std::path::Path;
+///
+/// let paths = [Path::new("/bin"), Path::new("/usr/bin")];
+/// let path_os_string = env::join_paths(paths.iter()).unwrap();
+/// assert_eq!(path_os_string, OsString::from("/bin:/usr/bin"));
+/// # }
+/// ```
+///
+/// Joining a path containing a colon on a Unix-like platform results in an error:
+///
+/// ```
+/// # if cfg!(unix) {
+/// use std::env;
+/// use std::path::Path;
+///
+/// let paths = [Path::new("/bin"), Path::new("/usr/bi:n")];
+/// assert!(env::join_paths(paths.iter()).is_err());
+/// # }
+/// ```
+///
+/// Using `env::join_paths` with `env::spit_paths` to append an item to the `PATH` environment
+/// variable:
+///
 /// ```
 /// use std::env;
 /// use std::path::PathBuf;