pub struct PathRef<'a> { /* private fields */ }Expand description
Borrowed view of a URI path.
The backing bytes preserve the parsed path representation. Use
as_encoded_str for a whole-path presentation.
Decode path data segment-by-segment via PathRef::segments and
PathSegment::as_decoded_str so encoded delimiters such as %2F
cannot be confused with structural / separators.
Implementations§
Source§impl<'a> PathRef<'a>
impl<'a> PathRef<'a>
Sourcepub fn from_raw_str(path: &'a str) -> Self
pub fn from_raw_str(path: &'a str) -> Self
Borrow a raw string as a PathRef — no allocation,
no unsafe. Note that it can mean that invalid characters are not yet pct-encoded,
this is fine as for comparison/hashing purposes it is handled fine.
Sourcepub fn as_encoded_str(self) -> Cow<'a, str>
pub fn as_encoded_str(self) -> Cow<'a, str>
Percent-encoded path.
Sourcepub fn trimmed_slashes(self) -> Self
pub fn trimmed_slashes(self) -> Self
Path view with every leading and trailing / removed.
Sourcepub fn segment_range(self, start: usize, count: usize) -> Option<Self>
pub fn segment_range(self, start: usize, count: usize) -> Option<Self>
Borrow a window of count consecutive path segments starting at
start.
When the window begins after an earlier segment, the returned view
includes the / delimiter immediately before the first selected
segment, making it directly usable with rooted PathPatterns.
Returns None when the requested window is empty or extends beyond the
available segments.
Sourcepub fn segments(self) -> PathSegments<'a> ⓘ
pub fn segments(self) -> PathSegments<'a> ⓘ
Iterator over path segments — the parts between / separators.
Matches url::Url::path_segments: an empty path yields no
segments, a leading / is the delimiter (not a segment), and a
trailing / yields a final empty segment (so /foo and /foo/
stay distinct). Opaque paths (no leading /, e.g. the path of
data:text/plain) split from the first byte.
"/" -> [""]
"/foo/" -> ["foo", ""]
"/a//b" -> ["a", "", "b"]Sourcepub fn has_prefix(self, prefix: impl IntoUriComponent) -> bool
pub fn has_prefix(self, prefix: impl IntoUriComponent) -> bool
true when the path begins with prefix — matched at / segment
boundaries, comparing percent-decoded segment values. Shortcut for
has_prefix_with_opts with the default
PathMatchOptions.
Sourcepub fn has_prefix_with_opts(
self,
prefix: impl IntoUriComponent,
opts: PathMatchOptions,
) -> bool
pub fn has_prefix_with_opts( self, prefix: impl IntoUriComponent, opts: PathMatchOptions, ) -> bool
true when the path begins with prefix under opts.
Sourcepub fn has_suffix(self, suffix: impl IntoUriComponent) -> bool
pub fn has_suffix(self, suffix: impl IntoUriComponent) -> bool
true when the path ends with suffix — matched at / segment
boundaries, comparing percent-decoded segment values. Shortcut for
has_suffix_with_opts with the default
PathMatchOptions.
Sourcepub fn has_suffix_with_opts(
self,
suffix: impl IntoUriComponent,
opts: PathMatchOptions,
) -> bool
pub fn has_suffix_with_opts( self, suffix: impl IntoUriComponent, opts: PathMatchOptions, ) -> bool
true when the path ends with suffix under opts.
Sourcepub fn nth_segment(self, n: usize) -> Option<PathSegment<'a>>
pub fn nth_segment(self, n: usize) -> Option<PathSegment<'a>>
The n-th path segment (0-based), or None when the path has fewer
segments. See segments for the splitting rules.
Sourcepub fn first_segment(self) -> Option<PathSegment<'a>>
pub fn first_segment(self) -> Option<PathSegment<'a>>
The first path segment, or None for an empty path.
Sourcepub fn last_segment(self) -> Option<PathSegment<'a>>
pub fn last_segment(self) -> Option<PathSegment<'a>>
The last path segment, or None for an empty path. A trailing /
yields a final empty segment, so /foo/’s last segment is "".
Sourcepub fn segment_count(self) -> usize
pub fn segment_count(self) -> usize
Number of path segments. O(n) in the path length.
Sourcepub fn contains_segments(self, needle: impl IntoUriComponent) -> bool
pub fn contains_segments(self, needle: impl IntoUriComponent) -> bool
true when needle’s segment(s) appear as a consecutive run of whole
path segments — matched at / boundaries with percent-decoded values
(default PathMatchOptions). E.g. contains_segments("@v") is true
for /golang.org/x/mod/@v/list, and false for /x/@version/y.
Sourcepub fn contains_segments_with_opts(
self,
needle: impl IntoUriComponent,
opts: PathMatchOptions,
) -> bool
pub fn contains_segments_with_opts( self, needle: impl IntoUriComponent, opts: PathMatchOptions, ) -> bool
true when needle’s segment(s) appear as a consecutive run of whole
path segments under opts.
Sourcepub fn is_pattern_match(self, pattern: &PathPattern) -> bool
pub fn is_pattern_match(self, pattern: &PathPattern) -> bool
true when path matches given PathPattern.
Shortcut for PathPattern::is_match.
Sourcepub fn pattern_captures(
self,
pattern: &PathPattern,
) -> Option<PathCaptures<'_, 'a>>
pub fn pattern_captures( self, pattern: &PathPattern, ) -> Option<PathCaptures<'_, 'a>>
Match using the given PathPattern
and return captured values, or None when path doesn’t
match. May allocate a small Vec for the bindings.
Shortcut for PathPattern::captures.
Trait Implementations§
impl<'a> Copy for PathRef<'a>
impl Eq for PathRef<'_>
impl IntoUriComponent for PathRef<'_>
Source§impl Ord for PathRef<'_>
impl Ord for PathRef<'_>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Auto Trait Implementations§
impl<'a> Freeze for PathRef<'a>
impl<'a> RefUnwindSafe for PathRef<'a>
impl<'a> Send for PathRef<'a>
impl<'a> Sync for PathRef<'a>
impl<'a> Unpin for PathRef<'a>
impl<'a> UnsafeUnpin for PathRef<'a>
impl<'a> UnwindSafe for PathRef<'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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
Source§impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for Twhere
U: RamaTryFrom<T, CrateMarker>,
impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for Twhere
U: RamaTryFrom<T, CrateMarker>,
type Error = <U as RamaTryFrom<T, CrateMarker>>::Error
fn rama_try_into(self) -> Result<U, <U as RamaTryFrom<T, CrateMarker>>::Error>
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<V, F> ValueFormatter<&V> for F
impl<V, F> ValueFormatter<&V> for F
Source§const SHAPE: FieldShape<'static>
const SHAPE: FieldShape<'static>
metrique_require_explicit_impls only.Source§fn format_value(writer: impl ValueWriter, value: &&V)
fn format_value(writer: impl ValueWriter, value: &&V)
value to writerSource§impl<V, F> ValueFormatter<Arc<V>> for F
impl<V, F> ValueFormatter<Arc<V>> for F
Source§const SHAPE: FieldShape<'static>
const SHAPE: FieldShape<'static>
metrique_require_explicit_impls only.Source§fn format_value(writer: impl ValueWriter, value: &Arc<V>)
fn format_value(writer: impl ValueWriter, value: &Arc<V>)
value to writerSource§impl<V, F> ValueFormatter<Box<V>> for F
impl<V, F> ValueFormatter<Box<V>> for F
Source§const SHAPE: FieldShape<'static>
const SHAPE: FieldShape<'static>
metrique_require_explicit_impls only.Source§fn format_value(writer: impl ValueWriter, value: &Box<V>)
fn format_value(writer: impl ValueWriter, value: &Box<V>)
value to writerSource§impl<V, F> ValueFormatter<Cow<'_, V>> for F
impl<V, F> ValueFormatter<Cow<'_, V>> for F
Source§const SHAPE: FieldShape<'static>
const SHAPE: FieldShape<'static>
metrique_require_explicit_impls only.Source§fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)
fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)
value to writerSource§impl<V, F> ValueFormatter<Option<V>> for Fwhere
F: ValueFormatter<V> + ?Sized,
impl<V, F> ValueFormatter<Option<V>> for Fwhere
F: ValueFormatter<V> + ?Sized,
Source§const SHAPE: FieldShape<'static>
const SHAPE: FieldShape<'static>
metrique_require_explicit_impls only.Source§fn format_value(writer: impl ValueWriter, value: &Option<V>)
fn format_value(writer: impl ValueWriter, value: &Option<V>)
value to writer