Struct uriparse::path::Path [−][src]
pub struct Path<'path> { /* fields omitted */ }
The path component as defined in [RFC3986, Section 3.3].
A path is composed of a sequence of segments. It is also either absolute or relative, where an
absolute path starts with a '/'
. A URI with an authority always has an absolute path
regardless of whether or not the path was empty (i.e. "http://example.com" has a single empty
path segment and is absolute).
Methods
impl<'path> Path<'path>
[src]
impl<'path> Path<'path>
pub fn clear(&mut self)
[src]
pub fn clear(&mut self)
Clears all segments from the path leaving a single empty segment.
Examples
use std::convert::TryFrom; use uriparse::Path; let mut path = Path::try_from("/my/path").unwrap(); assert_eq!(path, "/my/path"); path.clear(); assert_eq!(path, "/");
pub fn into_owned(self) -> Path<'static>
[src]
pub fn into_owned(self) -> Path<'static>
Converts the Path
into an owned copy.
If you construct the path from a source with a non-static lifetime, you may run into lifetime problems due to the way the struct is designed. Calling this function will ensure that the returned value has a static lifetime.
This is different from just cloning. Cloning the path will just copy the references, and thus the lifetime will remain the same.
pub fn is_absolute(&self) -> bool
[src]
pub fn is_absolute(&self) -> bool
Returns whether or not the path is absolute (i.e. it starts with a '/'
).
Any path following an [Authority
] will always be parsed to be absolute.
Examples
use std::convert::TryFrom; use uriparse::Path; let path = Path::try_from("/my/path").unwrap(); assert_eq!(path.is_absolute(), true);
pub fn pop(&mut self)
[src]
pub fn pop(&mut self)
Pops the last segment off of the path.
If the path only contains one segment, then that segment will become empty.
use std::convert::TryFrom; use uriparse::Path; let mut path = Path::try_from("/my/path").unwrap(); path.pop(); assert_eq!(path, "/my"); path.pop(); assert_eq!(path, "/");
pub fn push<S, E>(&mut self, segment: S) -> Result<(), InvalidPath> where
Segment<'path>: TryFrom<S, Error = E>,
InvalidPath: From<E>,
[src]
pub fn push<S, E>(&mut self, segment: S) -> Result<(), InvalidPath> where
Segment<'path>: TryFrom<S, Error = E>,
InvalidPath: From<E>,
Pushes a segment onto the path.
If the conversion to a Segment
fails, an InvalidPath
will be returned.
use std::convert::TryFrom; use uriparse::Path; let mut path = Path::try_from("/my/path").unwrap(); path.push("test"); assert_eq!(path, "/my/path/test");
pub fn segments(&self) -> &[Segment<'path>]
[src]
pub fn segments(&self) -> &[Segment<'path>]
Returns the segments of the path.
If you require mutability, use Path::segments_mut
.
Examples
use std::convert::TryFrom; use uriparse::Path; let mut path = Path::try_from("/my/path").unwrap(); assert_eq!(path.segments()[1], "path");
pub fn segments_mut(&mut self) -> &mut [Segment<'path>]
[src]
pub fn segments_mut(&mut self) -> &mut [Segment<'path>]
Returns the segments of the path mutably.
Due to the required restriction that there must be at least one segment in a path, this mutability only applies to the segments themselves, not the container.
Examples
use std::convert::TryFrom; use uriparse::{Path, Segment}; let mut path = Path::try_from("/my/path").unwrap(); // TODO: Remove this block once NLL is stable. { let mut segments = path.segments_mut(); segments[1] = Segment::try_from("test").unwrap(); } assert_eq!(path, "/my/test");
pub fn set_absolute(&mut self, absolute: bool)
[src]
pub fn set_absolute(&mut self, absolute: bool)
Sets whether or not the path is absolute (i.e. it starts with a '/'
).
Examples
use std::convert::TryFrom; use uriparse::Path; let mut path = Path::try_from("/my/path").unwrap(); path.set_absolute(false); assert_eq!(path, "my/path");
Trait Implementations
impl<'path> Clone for Path<'path>
[src]
impl<'path> Clone for Path<'path>
fn clone(&self) -> Path<'path>
[src]
fn clone(&self) -> Path<'path>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<'path> Debug for Path<'path>
[src]
impl<'path> Debug for Path<'path>
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<'path> Eq for Path<'path>
[src]
impl<'path> Eq for Path<'path>
impl<'path> Hash for Path<'path>
[src]
impl<'path> Hash for Path<'path>
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<'path> PartialEq for Path<'path>
[src]
impl<'path> PartialEq for Path<'path>
fn eq(&self, other: &Path<'path>) -> bool
[src]
fn eq(&self, other: &Path<'path>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Path<'path>) -> bool
[src]
fn ne(&self, other: &Path<'path>) -> bool
This method tests for !=
.
impl<'path> Display for Path<'path>
[src]
impl<'path> Display for Path<'path>
fn fmt(&self, formatter: &mut Formatter) -> Result
[src]
fn fmt(&self, formatter: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<'path> From<Path<'path>> for String
[src]
impl<'path> From<Path<'path>> for String
impl<'path> PartialEq<[u8]> for Path<'path>
[src]
impl<'path> PartialEq<[u8]> for Path<'path>
fn eq(&self, other: &[u8]) -> bool
[src]
fn eq(&self, other: &[u8]) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<'path> PartialEq<Path<'path>> for [u8]
[src]
impl<'path> PartialEq<Path<'path>> for [u8]
fn eq(&self, other: &Path<'path>) -> bool
[src]
fn eq(&self, other: &Path<'path>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<'a, 'path> PartialEq<&'a [u8]> for Path<'path>
[src]
impl<'a, 'path> PartialEq<&'a [u8]> for Path<'path>
fn eq(&self, other: &&'a [u8]) -> bool
[src]
fn eq(&self, other: &&'a [u8]) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<'a, 'path> PartialEq<Path<'path>> for &'a [u8]
[src]
impl<'a, 'path> PartialEq<Path<'path>> for &'a [u8]
fn eq(&self, other: &Path<'path>) -> bool
[src]
fn eq(&self, other: &Path<'path>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<'path> PartialEq<str> for Path<'path>
[src]
impl<'path> PartialEq<str> for Path<'path>
fn eq(&self, other: &str) -> bool
[src]
fn eq(&self, other: &str) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<'path> PartialEq<Path<'path>> for str
[src]
impl<'path> PartialEq<Path<'path>> for str
fn eq(&self, other: &Path<'path>) -> bool
[src]
fn eq(&self, other: &Path<'path>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<'a, 'path> PartialEq<&'a str> for Path<'path>
[src]
impl<'a, 'path> PartialEq<&'a str> for Path<'path>
fn eq(&self, other: &&'a str) -> bool
[src]
fn eq(&self, other: &&'a str) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<'a, 'path> PartialEq<Path<'path>> for &'a str
[src]
impl<'a, 'path> PartialEq<Path<'path>> for &'a str
fn eq(&self, other: &Path<'path>) -> bool
[src]
fn eq(&self, other: &Path<'path>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<'path> TryFrom<&'path [u8]> for Path<'path>
[src]
impl<'path> TryFrom<&'path [u8]> for Path<'path>
type Error = InvalidPath
try_from
)The type returned in the event of a conversion error.
fn try_from(value: &'path [u8]) -> Result<Self, Self::Error>
[src]
fn try_from(value: &'path [u8]) -> Result<Self, Self::Error>
try_from
)Performs the conversion.
impl<'path> TryFrom<&'path str> for Path<'path>
[src]
impl<'path> TryFrom<&'path str> for Path<'path>