diff options
| author | kennytm <kennytm@gmail.com> | 2018-05-16 23:22:54 +0800 |
|---|---|---|
| committer | kennytm <kennytm@gmail.com> | 2018-05-17 05:18:09 +0800 |
| commit | 06e617386858a2a2b7d0ad11e3d59b932d6d378e (patch) | |
| tree | ce0c65a7a40a3e5fda260316aee90105b093f804 /src/libstd | |
| parent | 539a376c7ec6b7397a8f41ba6962ade376a8b44a (diff) | |
| parent | f73c4a47682870f7eabac63882da7255eca0b463 (diff) | |
| download | rust-06e617386858a2a2b7d0ad11e3d59b932d6d378e.tar.gz rust-06e617386858a2a2b7d0ad11e3d59b932d6d378e.zip | |
Rollup merge of #50736 - udoprog:env-try-op, r=shepmaster
env: remove unwrap in examples in favor of try op
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/env.rs | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/src/libstd/env.rs b/src/libstd/env.rs index a103c0bdd59..91e417c64da 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -49,9 +49,11 @@ use sys::os as os_imp; /// ``` /// use std::env; /// -/// // We assume that we are in a valid directory. -/// let path = env::current_dir().unwrap(); -/// println!("The current directory is {}", path.display()); +/// fn main() -> std::io::Result<()> { +/// let path = env::current_dir()?; +/// println!("The current directory is {}", path.display()); +/// Ok(()) +/// } /// ``` #[stable(feature = "env", since = "1.0.0")] pub fn current_dir() -> io::Result<PathBuf> { @@ -441,15 +443,18 @@ pub struct JoinPathsError { /// 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")); +/// fn main() -> Result<(), env::JoinPathsError> { +/// # if cfg!(unix) { +/// let paths = [Path::new("/bin"), Path::new("/usr/bin")]; +/// let path_os_string = env::join_paths(paths.iter())?; +/// assert_eq!(path_os_string, OsString::from("/bin:/usr/bin")); /// # } +/// Ok(()) +/// } /// ``` /// /// Joining a path containing a colon on a Unix-like platform results in an error: @@ -471,11 +476,15 @@ pub struct JoinPathsError { /// use std::env; /// use std::path::PathBuf; /// -/// if let Some(path) = env::var_os("PATH") { -/// let mut paths = env::split_paths(&path).collect::<Vec<_>>(); -/// paths.push(PathBuf::from("/home/xyz/bin")); -/// let new_path = env::join_paths(paths).unwrap(); -/// env::set_var("PATH", &new_path); +/// fn main() -> Result<(), env::JoinPathsError> { +/// if let Some(path) = env::var_os("PATH") { +/// let mut paths = env::split_paths(&path).collect::<Vec<_>>(); +/// paths.push(PathBuf::from("/home/xyz/bin")); +/// let new_path = env::join_paths(paths)?; +/// env::set_var("PATH", &new_path); +/// } +/// +/// Ok(()) /// } /// ``` #[stable(feature = "env", since = "1.0.0")] |
