pub enum TypedComponent<'a> {
Unix(UnixComponent<'a>),
Windows(WindowsComponent<'a>),
}
Expand description
Byte slice version of std::path::Component
that represents either a Unix or Windows path
component.
Variants§
Unix(UnixComponent<'a>)
Windows(WindowsComponent<'a>)
Implementations§
Source§impl<'a> TypedComponent<'a>
impl<'a> TypedComponent<'a>
Sourcepub fn as_bytes(&self) -> &'a [u8] ⓘ
pub fn as_bytes(&self) -> &'a [u8] ⓘ
Extracts the underlying [[u8]
] slice.
§Examples
use typed_path::{TypedComponent, TypedPath};
let path = TypedPath::derive(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(),
]);
Sourcepub fn is_root(&self) -> bool
pub fn is_root(&self) -> bool
Returns true if is the root dir component.
§Examples
use typed_path::{Component, UnixComponent, TypedComponent};
use std::convert::TryFrom;
let root_dir = TypedComponent::Unix(UnixComponent::try_from(b"/").unwrap());
assert!(root_dir.is_root());
let normal = TypedComponent::Unix(UnixComponent::try_from(b"file.txt").unwrap());
assert!(!normal.is_root());
Sourcepub fn is_normal(&self) -> bool
pub fn is_normal(&self) -> bool
Returns true if is a normal component.
§Examples
use typed_path::{Component, UnixComponent, TypedComponent};
use std::convert::TryFrom;
let normal = TypedComponent::Unix(UnixComponent::try_from(b"file.txt").unwrap());
assert!(normal.is_normal());
let root_dir = TypedComponent::Unix(UnixComponent::try_from(b"/").unwrap());
assert!(!root_dir.is_normal());
Sourcepub fn as_normal_bytes(&self) -> Option<&[u8]>
pub fn as_normal_bytes(&self) -> Option<&[u8]>
Returns bytes if is a normal component.
§Examples
use typed_path::{Component, UnixComponent, TypedComponent};
use std::convert::TryFrom;
let normal = TypedComponent::Unix(UnixComponent::try_from(b"file.txt").unwrap());
assert_eq!(normal.as_normal_bytes(), Some(b"file.txt".as_slice()));
let root_dir = TypedComponent::Unix(UnixComponent::try_from(b"/").unwrap());
assert_eq!(root_dir.as_normal_bytes(), None);
Sourcepub fn is_parent(&self) -> bool
pub fn is_parent(&self) -> bool
Returns true if is a parent directory component.
§Examples
use typed_path::{Component, UnixComponent, TypedComponent};
use std::convert::TryFrom;
let parent = TypedComponent::Unix(UnixComponent::try_from("..").unwrap());
assert!(parent.is_parent());
let root_dir = TypedComponent::Unix(UnixComponent::try_from("/").unwrap());
assert!(!root_dir.is_parent());
Sourcepub fn is_current(&self) -> bool
pub fn is_current(&self) -> bool
Returns true if is the current directory component.
§Examples
use typed_path::{Component, UnixComponent, TypedComponent};
use std::convert::TryFrom;
let current = TypedComponent::Unix(UnixComponent::try_from(".").unwrap());
assert!(current.is_current());
let root_dir = TypedComponent::Unix(UnixComponent::try_from("/").unwrap());
assert!(!root_dir.is_current());
pub fn is_empty(&self) -> bool
Trait Implementations§
Source§impl AsRef<[u8]> for TypedComponent<'_>
impl AsRef<[u8]> for TypedComponent<'_>
Source§impl<'a> Clone for TypedComponent<'a>
impl<'a> Clone for TypedComponent<'a>
Source§fn clone(&self) -> TypedComponent<'a>
fn clone(&self) -> TypedComponent<'a>
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<'a> Debug for TypedComponent<'a>
impl<'a> Debug for TypedComponent<'a>
Source§impl<'a> Hash for TypedComponent<'a>
impl<'a> Hash for TypedComponent<'a>
Source§impl<'a> Ord for TypedComponent<'a>
impl<'a> Ord for TypedComponent<'a>
Source§fn cmp(&self, other: &TypedComponent<'a>) -> Ordering
fn cmp(&self, other: &TypedComponent<'a>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<'a> PartialEq for TypedComponent<'a>
impl<'a> PartialEq for TypedComponent<'a>
Source§impl<'a> PartialOrd for TypedComponent<'a>
impl<'a> PartialOrd for TypedComponent<'a>
impl<'a> Copy for TypedComponent<'a>
impl<'a> Eq for TypedComponent<'a>
impl<'a> StructuralPartialEq for TypedComponent<'a>
Auto Trait Implementations§
impl<'a> Freeze for TypedComponent<'a>
impl<'a> RefUnwindSafe for TypedComponent<'a>
impl<'a> Send for TypedComponent<'a>
impl<'a> Sync for TypedComponent<'a>
impl<'a> Unpin for TypedComponent<'a>
impl<'a> UnwindSafe for TypedComponent<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more