Skip to content

Commit

Permalink
add PathDir::current_dir
Browse files Browse the repository at this point in the history
  • Loading branch information
vitiral committed Feb 10, 2018
1 parent 1104b2c commit 72c767c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ license = "MIT OR Apache-2.0"
name = "path_abs"
readme = "README.md"
repository = "https://github.com/vitiral/path_abs"
version = "0.3.15"
version = "0.3.16"

[dependencies]
std_prelude = "0.2.12"
Expand Down
20 changes: 20 additions & 0 deletions src/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,25 @@ impl PathDir {
PathDir::from_abs(abs)
}

/// Returns the current working directory from the `env` as a `PathDir`.
///
/// # Examples
/// ```rust
/// # extern crate path_abs;
/// use path_abs::PathDir;
/// # fn try_main() -> ::std::io::Result<()> {
/// let cwd = PathDir::current_dir()?;
/// # let env_cwd = ::std::fs::canonicalize(::std::env::current_dir()?)?;
/// # let cwd_ref: &::std::path::PathBuf = cwd.as_ref();
/// # assert_eq!(cwd_ref, &env_cwd);
/// # Ok(()) } fn main() { try_main().unwrap() }
/// ```
pub fn current_dir() -> Result<PathDir> {
let dir = ::std::env::current_dir()
.map_err(|err| Error::new(err, "getting current_dir", PathArc::new("$CWD")))?;
PathDir::new(dir)
}

/// Consume the `PathAbs` validating that the path is a directory and returning `PathDir`. The
/// directory must exist or `io::Error` will be returned.
///
Expand Down Expand Up @@ -69,6 +88,7 @@ impl PathDir {
}
}


#[inline(always)]
/// Do the conversion _without checking_.
///
Expand Down

0 comments on commit 72c767c

Please sign in to comment.