pub struct Path<'a>(/* private fields */);Expand description
A hierarchical identifier, such as a::b::c.
Paths have some logic for determining whether one path is a child of another but don’t handle relative/absolute paths or globs.
Implementations§
Source§impl Path<'static>
impl Path<'static>
Sourcepub fn new(path: &'static str) -> Result<Path<'static>, InvalidPathError>
pub fn new(path: &'static str) -> Result<Path<'static>, InvalidPathError>
Create a path from a raw value.
This method will fail if the path is malformed. A valid path consists of one or more identifiers separated by ::s. like a::b::c. See the is_valid_path function for more details.
Sourcepub const fn new_raw(path: &'static str) -> Path<'static>
pub const fn new_raw(path: &'static str) -> Path<'static>
Create a path from a raw value without checking its validity.
This method is not unsafe. There are no memory safety properties tied to the validity of paths. Code that uses path segments may panic or produce unexpected results if given an invalid path.
Source§impl<'a> Path<'a>
impl<'a> Path<'a>
Sourcepub fn new_ref(path: &'a str) -> Result<Path<'a>, InvalidPathError>
pub fn new_ref(path: &'a str) -> Result<Path<'a>, InvalidPathError>
Create a path from a raw borrowed value.
The Path::new method should be preferred where possible.
This method will fail if the path is malformed. A valid path consists of one or more identifiers separated by ::s. like a::b::c. See the is_valid_path function for more details.
Sourcepub const fn new_ref_raw(path: &'a str) -> Path<'a>
pub const fn new_ref_raw(path: &'a str) -> Path<'a>
Create a path from a raw borrowed value without checking its validity.
The Path::new_raw method should be preferred where possible.
This method is not unsafe. There are no memory safety properties tied to the validity of paths. Code that uses path segments may panic or produce unexpected results if given an invalid path.
Sourcepub fn new_str(path: Str<'a>) -> Result<Path<'a>, InvalidPathError>
pub fn new_str(path: Str<'a>) -> Result<Path<'a>, InvalidPathError>
Create a path from a raw Str value.
This method will fail if the path is malformed. A valid path consists of one or more identifiers separated by ::s. like a::b::c. See the is_valid_path function for more details.
Sourcepub const fn new_str_raw(path: Str<'a>) -> Path<'a>
pub const fn new_str_raw(path: Str<'a>) -> Path<'a>
Create a path from a raw Str value without checking its validity.
This method is not unsafe. There are no memory safety properties tied to the validity of paths. Code that uses path segments may panic or produce unexpected results if given an invalid path.
Sourcepub fn segments(&self) -> Segments<'_> ⓘ
pub fn segments(&self) -> Segments<'_> ⓘ
Iterate over the segments of the path.
The behavior of this method on invalid paths is undefined.
Sourcepub fn is_child_of<'b>(&self, other: &Path<'b>) -> bool
pub fn is_child_of<'b>(&self, other: &Path<'b>) -> bool
Whether this path is a child of other.
The path a is a child of the path b if b is a prefix of a up to a path segment. The path a::b is a child of a. The path c::a::b is not a child of a. The path aa::b is not a child of a.
This method is reflexive. A path is considered a child of itself.
The behavior of this method on invalid paths is undefined.
Source§impl Path<'static>
impl Path<'static>
Sourcepub fn new_owned(
path: impl Into<Box<str>>,
) -> Result<Path<'static>, InvalidPathError>
pub fn new_owned( path: impl Into<Box<str>>, ) -> Result<Path<'static>, InvalidPathError>
Create a path from an owned raw value.
This method will fail if the path is malformed. A valid path consists of one or more identifiers separated by ::s. like a::b::c. See the is_valid_path function for more details.
Sourcepub fn new_owned_raw(path: impl Into<Box<str>>) -> Path<'static>
pub fn new_owned_raw(path: impl Into<Box<str>>) -> Path<'static>
Create a path from an owned raw value without checking its validity.
This method is not unsafe. There are no memory safety properties tied to the validity of paths. Code that uses path segments may panic or produce unexpected results if given an invalid path.
Source§impl<'a> Path<'a>
impl<'a> Path<'a>
Sourcepub fn new_cow_ref(path: Cow<'a, str>) -> Result<Path<'a>, InvalidPathError>
pub fn new_cow_ref(path: Cow<'a, str>) -> Result<Path<'a>, InvalidPathError>
Create a path from a potentially owned raw value.
If the value is Cow::Borrowed then this method will defer to Path::new_ref. If the value is Cow::Owned then this method will defer to Path::new_owned.
This method will fail if the path is malformed. A valid path consists of one or more identifiers separated by ::s. like a::b::c. See the is_valid_path function for more details.
Sourcepub fn new_cow_ref_raw(path: Cow<'a, str>) -> Path<'a>
pub fn new_cow_ref_raw(path: Cow<'a, str>) -> Path<'a>
Create a path from a potentially owned raw value without checking its validity.
If the value is Cow::Borrowed then this method will defer to Path::new_ref_raw. If the value is Cow::Owned then this method will defer to Path::new_owned_raw.
This method is not unsafe. There are no memory safety properties tied to the validity of paths. Code that uses path segments may panic or produce unexpected results if given an invalid path.
Sourcepub fn to_owned(&self) -> Path<'static>
pub fn to_owned(&self) -> Path<'static>
Get a new path, taking an owned copy of the data in this one.
Trait Implementations§
Source§impl<'a> Ord for Path<'a>
impl<'a> Ord for Path<'a>
Source§impl<'a> PartialOrd for Path<'a>
impl<'a> PartialOrd for Path<'a>
Source§impl<'a> Serialize for Path<'a>
Available on crate feature serde only.
impl<'a> Serialize for Path<'a>
serde only.Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Source§impl<'a> Value for Path<'a>
Available on crate feature sval only.
impl<'a> Value for Path<'a>
sval only.Source§fn stream<'sval, S>(&'sval self, stream: &mut S) -> Result<(), Error>
fn stream<'sval, S>(&'sval self, stream: &mut S) -> Result<(), Error>
Stream.