pub enum UnixComponent<'a> {
    RootDir,
    CurDir,
    ParentDir,
    Normal(&'a [u8]),
}
Expand description

Byte slice version of std::path::Component that represents a Unix-specific component

Variants§

§

RootDir

§

CurDir

§

ParentDir

§

Normal(&'a [u8])

Implementations§

Returns path representing this specific component

Trait Implementations§

Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more

Extracts the underlying [[u8]] slice

Examples
use typed_path::{Component, UnixPath};

let path = UnixPath::new(b"/tmp/foo/../bar.txt");
let components: Vec<_> = path.components().map(|comp| comp.as_bytes()).collect();
assert_eq!(&components, &[
    b"/".as_slice(),
    b"tmp".as_slice(),
    b"foo".as_slice(),
    b"..".as_slice(),
    b"bar.txt".as_slice(),
]);

Returns true if is the root dir component

Examples
use typed_path::{Component, unix::UnixComponent};
use std::convert::TryFrom;

let root_dir = UnixComponent::try_from(b"/").unwrap();
assert!(root_dir.is_root());

let normal = UnixComponent::try_from(b"file.txt").unwrap();
assert!(!normal.is_root());

Returns true if is a normal component

Examples
use typed_path::{Component, unix::UnixComponent};
use std::convert::TryFrom;

let normal = UnixComponent::try_from(b"file.txt").unwrap();
assert!(normal.is_normal());

let root_dir = UnixComponent::try_from(b"/").unwrap();
assert!(!root_dir.is_normal());
Returns size of component in bytes
Returns true if component represents an empty byte slice
Formats the value using the given formatter. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
The type returned in the event of a conversion error.
Performs the conversion.

Parses the byte slice into a UnixComponent

Examples
use typed_path::unix::UnixComponent;
use std::convert::TryFrom;

// Supports parsing standard unix path components
assert_eq!(UnixComponent::try_from(b"/"), Ok(UnixComponent::RootDir));
assert_eq!(UnixComponent::try_from(b"."), Ok(UnixComponent::CurDir));
assert_eq!(UnixComponent::try_from(b".."), Ok(UnixComponent::ParentDir));
assert_eq!(UnixComponent::try_from(b"file.txt"), Ok(UnixComponent::Normal(b"file.txt")));
assert_eq!(UnixComponent::try_from(b"dir/"), Ok(UnixComponent::Normal(b"dir")));

// Parsing more than one component will fail
assert!(UnixComponent::try_from(b"/file").is_err());
The type returned in the event of a conversion error.
The type returned in the event of a conversion error.
Performs the conversion.

Attempts to convert a std::path::Component into a UnixComponent, returning a result containing the new component when successful or the original component when failed

Examples
use std::convert::TryFrom;
use std::ffi::OsStr;
use std::path::Component;
use typed_path::unix::UnixComponent;

let component = UnixComponent::try_from(Component::RootDir).unwrap();
assert_eq!(component, UnixComponent::RootDir);

let component = UnixComponent::try_from(Component::CurDir).unwrap();
assert_eq!(component, UnixComponent::CurDir);

let component = UnixComponent::try_from(Component::ParentDir).unwrap();
assert_eq!(component, UnixComponent::ParentDir);

let component = UnixComponent::try_from(Component::Normal(OsStr::new("file.txt"))).unwrap();
assert_eq!(component, UnixComponent::Normal(b"file.txt"));
The type returned in the event of a conversion error.

Attempts to convert a UnixComponent into a std::path::Component, returning a result containing the new path when successful or the original path when failed

Examples
use std::convert::TryFrom;
use std::ffi::OsStr;
use std::path::Component;
use typed_path::unix::UnixComponent;

let component = Component::try_from(UnixComponent::RootDir).unwrap();
assert_eq!(component, Component::RootDir);

let component = Component::try_from(UnixComponent::CurDir).unwrap();
assert_eq!(component, Component::CurDir);

let component = Component::try_from(UnixComponent::ParentDir).unwrap();
assert_eq!(component, Component::ParentDir);

let component = Component::try_from(UnixComponent::Normal(b"file.txt")).unwrap();
assert_eq!(component, Component::Normal(OsStr::new("file.txt")));
The type returned in the event of a conversion error.
The type returned in the event of a conversion error.
Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.