@@ -49,9 +49,11 @@ use sys::os as os_imp;
49
49
/// ```
50
50
/// use std::env;
51
51
///
52
- /// // We assume that we are in a valid directory.
53
- /// let path = env::current_dir().unwrap();
54
- /// println!("The current directory is {}", path.display());
52
+ /// fn main() -> std::io::Result<()> {
53
+ /// let path = env::current_dir()?;
54
+ /// println!("The current directory is {}", path.display());
55
+ /// Ok(())
56
+ /// }
55
57
/// ```
56
58
#[ stable( feature = "env" , since = "1.0.0" ) ]
57
59
pub fn current_dir ( ) -> io:: Result < PathBuf > {
@@ -441,15 +443,18 @@ pub struct JoinPathsError {
441
443
/// Joining paths on a Unix-like platform:
442
444
///
443
445
/// ```
444
- /// # if cfg!(unix) {
445
446
/// use std::env;
446
447
/// use std::ffi::OsString;
447
448
/// use std::path::Path;
448
449
///
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"));
450
+ /// fn main() -> Result<(), env::JoinPathsError> {
451
+ /// # if cfg!(unix) {
452
+ /// let paths = [Path::new("/bin"), Path::new("/usr/bin")];
453
+ /// let path_os_string = env::join_paths(paths.iter())?;
454
+ /// assert_eq!(path_os_string, OsString::from("/bin:/usr/bin"));
452
455
/// # }
456
+ /// Ok(())
457
+ /// }
453
458
/// ```
454
459
///
455
460
/// Joining a path containing a colon on a Unix-like platform results in an error:
@@ -471,11 +476,15 @@ pub struct JoinPathsError {
471
476
/// use std::env;
472
477
/// use std::path::PathBuf;
473
478
///
474
- /// if let Some(path) = env::var_os("PATH") {
475
- /// let mut paths = env::split_paths(&path).collect::<Vec<_>>();
476
- /// paths.push(PathBuf::from("/home/xyz/bin"));
477
- /// let new_path = env::join_paths(paths).unwrap();
478
- /// env::set_var("PATH", &new_path);
479
+ /// fn main() -> Result<(), env::JoinPathsError> {
480
+ /// if let Some(path) = env::var_os("PATH") {
481
+ /// let mut paths = env::split_paths(&path).collect::<Vec<_>>();
482
+ /// paths.push(PathBuf::from("/home/xyz/bin"));
483
+ /// let new_path = env::join_paths(paths)?;
484
+ /// env::set_var("PATH", &new_path);
485
+ /// }
486
+ ///
487
+ /// Ok(())
479
488
/// }
480
489
/// ```
481
490
#[ stable( feature = "env" , since = "1.0.0" ) ]
0 commit comments