pub enum Utf8TypedComponent<'a> {
Unix(Utf8UnixComponent<'a>),
Windows(Utf8WindowsComponent<'a>),
}
Expand description
Str slice version of std::path::Component
that represents either a Unix or Windows path
component.
Variants§
Unix(Utf8UnixComponent<'a>)
Windows(Utf8WindowsComponent<'a>)
Implementations§
Source§impl<'a> Utf8TypedComponent<'a>
impl<'a> Utf8TypedComponent<'a>
Sourcepub fn to_path(&self) -> Utf8TypedPath<'a>
pub fn to_path(&self) -> Utf8TypedPath<'a>
Returns path representing this specific component.
Sourcepub fn as_str(&self) -> &'a str
pub fn as_str(&self) -> &'a str
Extracts the underlying str
slice.
§Examples
use typed_path::{Utf8TypedComponent, Utf8TypedPath};
let path = Utf8TypedPath::derive("/tmp/foo/../bar.txt");
let components: Vec<_> = path.components().map(|comp| comp.as_str()).collect();
assert_eq!(&components, &[
"/",
"tmp",
"foo",
"..",
"bar.txt",
]);
Sourcepub fn is_root(&self) -> bool
pub fn is_root(&self) -> bool
Returns true if is the root dir component.
§Examples
use typed_path::{Utf8Component, Utf8UnixComponent, Utf8TypedComponent};
use std::convert::TryFrom;
let root_dir = Utf8TypedComponent::Unix(Utf8UnixComponent::try_from("/").unwrap());
assert!(root_dir.is_root());
let normal = Utf8TypedComponent::Unix(Utf8UnixComponent::try_from("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::{Utf8Component, Utf8UnixComponent, Utf8TypedComponent};
use std::convert::TryFrom;
let normal = Utf8TypedComponent::Unix(Utf8UnixComponent::try_from("file.txt").unwrap());
assert!(normal.is_normal());
let root_dir = Utf8TypedComponent::Unix(Utf8UnixComponent::try_from("/").unwrap());
assert!(!root_dir.is_normal());
Sourcepub fn as_normal_str(&self) -> Option<&str>
pub fn as_normal_str(&self) -> Option<&str>
Returns str if is a normal component.
§Examples
use typed_path::{Utf8Component, Utf8UnixComponent, Utf8TypedComponent};
use std::convert::TryFrom;
let normal = Utf8TypedComponent::Unix(Utf8UnixComponent::try_from("file.txt").unwrap());
assert_eq!(normal.as_normal_str(), Some("file.txt"));
let root_dir = Utf8TypedComponent::Unix(Utf8UnixComponent::try_from("/").unwrap());
assert_eq!(root_dir.as_normal_str(), 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::{Utf8Component, Utf8UnixComponent, Utf8TypedComponent};
use std::convert::TryFrom;
let parent = Utf8TypedComponent::Unix(Utf8UnixComponent::try_from("..").unwrap());
assert!(parent.is_parent());
let root_dir = Utf8TypedComponent::Unix(Utf8UnixComponent::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::{Utf8Component, Utf8UnixComponent, Utf8TypedComponent};
use std::convert::TryFrom;
let current = Utf8TypedComponent::Unix(Utf8UnixComponent::try_from(".").unwrap());
assert!(current.is_current());
let root_dir = Utf8TypedComponent::Unix(Utf8UnixComponent::try_from("/").unwrap());
assert!(!root_dir.is_current());
pub fn is_empty(&self) -> bool
Trait Implementations§
Source§impl AsRef<[u8]> for Utf8TypedComponent<'_>
impl AsRef<[u8]> for Utf8TypedComponent<'_>
Source§impl AsRef<str> for Utf8TypedComponent<'_>
impl AsRef<str> for Utf8TypedComponent<'_>
Source§impl<'a> Clone for Utf8TypedComponent<'a>
impl<'a> Clone for Utf8TypedComponent<'a>
Source§fn clone(&self) -> Utf8TypedComponent<'a>
fn clone(&self) -> Utf8TypedComponent<'a>
Returns a duplicate of the value. Read more
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<'a> Debug for Utf8TypedComponent<'a>
impl<'a> Debug for Utf8TypedComponent<'a>
Source§impl Display for Utf8TypedComponent<'_>
impl Display for Utf8TypedComponent<'_>
Source§impl<'a> Hash for Utf8TypedComponent<'a>
impl<'a> Hash for Utf8TypedComponent<'a>
Source§impl<'a> Ord for Utf8TypedComponent<'a>
impl<'a> Ord for Utf8TypedComponent<'a>
Source§fn cmp(&self, other: &Utf8TypedComponent<'a>) -> Ordering
fn cmp(&self, other: &Utf8TypedComponent<'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 Utf8TypedComponent<'a>
impl<'a> PartialEq for Utf8TypedComponent<'a>
Source§impl<'a> PartialOrd for Utf8TypedComponent<'a>
impl<'a> PartialOrd for Utf8TypedComponent<'a>
impl<'a> Copy for Utf8TypedComponent<'a>
impl<'a> Eq for Utf8TypedComponent<'a>
impl<'a> StructuralPartialEq for Utf8TypedComponent<'a>
Auto Trait Implementations§
impl<'a> Freeze for Utf8TypedComponent<'a>
impl<'a> RefUnwindSafe for Utf8TypedComponent<'a>
impl<'a> Send for Utf8TypedComponent<'a>
impl<'a> Sync for Utf8TypedComponent<'a>
impl<'a> Unpin for Utf8TypedComponent<'a>
impl<'a> UnwindSafe for Utf8TypedComponent<'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