Struct path_abs::PathDir [−][src]
A PathAbs
that is guaranteed to be a directory, with associated methods.
Implementations
impl PathDir
[src]
pub fn new<P: AsRef<Path>>(path: P) -> Result<PathDir>
[src]
Instantiate a new PathDir
. The directory must exist or io::Error
will be returned.
Returns io::ErrorKind::InvalidInput
if the path exists but is not a directory.
Examples
use path_abs::PathDir; let src = PathDir::new("src")?;
pub fn new_unchecked<P: Into<Arc<PathBuf>>>(path: P) -> PathDir
[src]
Create a PathDir
unchecked.
This is mostly used for constructing during tests, or if the path was previously validated.
This is effectively the same as a Arc<PathBuf>
.
Note: This is memory safe, so is not marked
unsafe
. However, it could cause panics in some methods if the path was not properly validated.
pub fn current_dir() -> Result<PathDir>
[src]
Returns the current working directory from the env
as a PathDir
.
Examples
use path_abs::PathDir; let cwd = PathDir::current_dir()?;
pub fn try_from<P: Into<PathAbs>>(path: P) -> Result<PathDir>
[src]
Consume the PathAbs
validating that the path is a directory and returning PathDir
. The
directory must exist or io::Error
will be returned.
If the path is actually a file returns io::ErrorKind::InvalidInput
.
Examples
use path_abs::{PathAbs, PathDir}; let src_abs = PathAbs::new("src")?; let src_dir = PathDir::try_from(src_abs)?;
pub fn create<P: AsRef<Path>>(path: P) -> Result<PathDir>
[src]
Instantiate a new PathDir
to a directory, creating the directory if it doesn't exist.
Examples
use path_abs::PathDir; let example = "example"; let dir = PathDir::create(example)?; // It can be done twice with no effect. let _ = PathDir::create(example)?;
pub fn create_all<P: AsRef<Path>>(path: P) -> Result<PathDir>
[src]
Instantiate a new PathDir
to a directory, recursively recreating it and all of its parent
components if they are missing.
Examples
use path_abs::PathDir; let example = "example/long/path"; let path = PathDir::create_all(example)?; // It can be done twice with no effect. let _ = PathDir::create_all(example)?;
pub fn join_abs<P: AsRef<Path>>(&self, path: P) -> Result<PathType>
[src]
Join a path onto the PathDir
, expecting it to exist. Returns the resulting PathType
.
Examples
use path_abs::{PathDir, PathFile, PathInfo}; let src = PathDir::new("src")?; let lib = src.join_abs("lib.rs")?.unwrap_file(); assert!(lib.is_file());
pub fn list(&self) -> Result<ListDir>
[src]
List the contents of the directory, returning an iterator of PathType
s.
Examples
use std::collections::HashSet; use path_abs::{PathDir, PathFile, PathType, PathOps}; let example = "example"; let example_dir = PathDir::create(example)?; let foo_dir = PathDir::create(example_dir.concat("foo")?)?; let bar_file = PathFile::create(example_dir.concat("bar.txt")?)?; let mut result = HashSet::new(); for p in example_dir.list()? { result.insert(p?); } let mut expected = HashSet::new(); expected.insert(PathType::Dir(foo_dir)); expected.insert(PathType::File(bar_file)); assert_eq!(expected, result);
pub fn remove(self) -> Result<()>
[src]
Remove (delete) the empty directory from the filesystem, consuming self.
Examples
use std::path::Path; use path_abs::PathDir; let example = Path::new("example/long/path"); let dir = PathDir::create_all(example)?; let parent = dir.parent_dir().unwrap(); assert!(example.exists()); dir.remove()?; // assert!(dir.exists()); <--- COMPILE ERROR assert!(!example.exists()); parent.remove()?;
pub fn remove_all(self) -> Result<()>
[src]
Remove (delete) the directory, after recursively removing its contents. Use carefully!
Examples
use std::path::Path; use path_abs::PathDir; let example = Path::new("example/long/path"); let dir = PathDir::create_all(example)?; let parent = dir.parent_dir().unwrap(); assert!(example.exists()); parent.remove_all()?; assert!(!example.exists());
pub fn symlink<P: AsRef<Path>>(&self, dst: P) -> Result<PathDir>
[src]
Creates a new symbolic link on the filesystem to the dst.
This handles platform specific behavior correctly.
Examples
use path_abs::{PathDir, PathFile, PathOps}; use std::path::Path; let example = "example"; let example_sym = "example_sym"; let dir = PathDir::create(example)?; let file = PathFile::create(dir.concat("example.txt")?)?; let dir_sym = dir.symlink(example_sym)?; // They have a different "absolute path" assert_ne!(dir, dir_sym); // But they can be canonicalized to the same file. let dir_can = dir_sym.canonicalize()?; assert_eq!(dir, dir_can);
pub fn as_path(&self) -> &Path
[src]
Return a reference to a basic std::path::Path
pub fn canonicalize(&self) -> Result<PathDir>
[src]
Returns the canonical form of the path with all intermediate components normalized and symbolic links resolved.
pub fn parent_dir(&self) -> Option<PathDir>
[src]
Get the parent directory of this directory as a PathDir
.
This does not make aditional syscalls, as the parent by definition must be a directory and exist.
Examples
use path_abs::PathDir; let src = PathDir::new("src")?; let proj = src.parent_dir().unwrap(); assert_eq!(PathDir::new("src/..")?, proj);
Trait Implementations
impl AsRef<OsStr> for PathDir
[src]
impl AsRef<Path> for PathDir
[src]
impl AsRef<PathAbs> for PathDir
[src]
impl AsRef<PathBuf> for PathDir
[src]
impl Borrow<Path> for PathDir
[src]
impl<'a> Borrow<Path> for &'a PathDir
[src]
impl Borrow<PathAbs> for PathDir
[src]
impl<'a> Borrow<PathAbs> for &'a PathDir
[src]
impl Borrow<PathBuf> for PathDir
[src]
impl<'a> Borrow<PathBuf> for &'a PathDir
[src]
impl Clone for PathDir
[src]
impl Debug for PathDir
[src]
impl<'de> Deserialize<'de> for PathDir
[src]
fn deserialize<D>(deserializer: D) -> Result<PathDir, D::Error> where
D: Deserializer<'de>,
[src]
D: Deserializer<'de>,
impl Eq for PathDir
[src]
impl From<PathDir> for PathAbs
[src]
impl Hash for PathDir
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for PathDir
[src]
fn cmp(&self, other: &PathDir) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl PartialEq<PathDir> for PathDir
[src]
impl PartialOrd<PathDir> for PathDir
[src]
fn partial_cmp(&self, other: &PathDir) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl PathOps for PathDir
[src]
type Output = PathAbs
fn concat<P: AsRef<Path>>(&self, path: P) -> Result<Self::Output>
[src]
fn join<P: AsRef<Path>>(&self, path: P) -> Self::Output
[src]
fn with_file_name<S: AsRef<OsStr>>(&self, file_name: S) -> Self::Output
[src]
fn with_extension<S: AsRef<OsStr>>(&self, extension: S) -> Self::Output
[src]
impl Serialize for PathDir
[src]
impl StructuralEq for PathDir
[src]
impl StructuralPartialEq for PathDir
[src]
Auto Trait Implementations
impl RefUnwindSafe for PathDir
impl Send for PathDir
impl Sync for PathDir
impl Unpin for PathDir
impl UnwindSafe for PathDir
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> PathInfo for T where
T: Clone + Borrow<PathBuf> + Into<Arc<PathBuf>>,
[src]
T: Clone + Borrow<PathBuf> + Into<Arc<PathBuf>>,
pub fn as_path(&Self) -> &Path
[src]
pub fn to_arc_pathbuf(&Self) -> Arc<PathBuf>
[src]
fn as_os_str(&self) -> &OsStr
[src]
fn to_str(&self) -> Option<&str>
[src]
fn to_string_lossy(&self) -> Cow<'_, str>
[src]
fn is_absolute(&self) -> bool
[src]
fn is_relative(&self) -> bool
[src]
fn has_root(&self) -> bool
[src]
fn ancestors(&self) -> Ancestors<'_>
[src]
fn file_name(&self) -> Option<&OsStr>
[src]
fn strip_prefix<P>(&self, base: P) -> Result<&Path, StripPrefixError> where
P: AsRef<Path>,
[src]
P: AsRef<Path>,
fn starts_with<P: AsRef<Path>>(&self, base: P) -> bool
[src]
fn ends_with<P: AsRef<Path>>(&self, base: P) -> bool
[src]
fn file_stem(&self) -> Option<&OsStr>
[src]
fn extension(&self) -> Option<&OsStr>
[src]
fn components(&self) -> Components<'_>
[src]
fn iter(&self) -> Iter<'_>
[src]
fn display(&self) -> Display<'_>
[src]
fn metadata(&self) -> Result<Metadata>
[src]
fn symlink_metadata(&self) -> Result<Metadata>
[src]
fn exists(&self) -> bool
[src]
fn is_file(&self) -> bool
[src]
fn is_dir(&self) -> bool
[src]
fn read_link(&self) -> Result<PathBuf>
[src]
fn canonicalize(&self) -> Result<PathAbs>
[src]
fn parent(&self) -> Result<&Path>
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToStfu8 for T where
T: Borrow<PathBuf>,
[src]
T: Borrow<PathBuf>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,