Struct PathRef
pub struct PathRef<'a> { /* private fields */ }net only.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§
§impl<'a> PathRef<'a>
impl<'a> PathRef<'a>
pub fn from_raw_str(path: &'a str) -> PathRef<'a>
pub fn from_raw_str(path: &'a str) -> PathRef<'a>
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.
pub fn as_encoded_str(self) -> Cow<'a, str>
pub fn as_encoded_str(self) -> Cow<'a, str>
Percent-encoded path.
pub fn trimmed_slashes(self) -> PathRef<'a>
pub fn trimmed_slashes(self) -> PathRef<'a>
Path view with every leading and trailing / removed.
pub fn segment_range(self, start: usize, count: usize) -> Option<PathRef<'a>>
pub fn segment_range(self, start: usize, count: usize) -> Option<PathRef<'a>>
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.
pub 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"]pub 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.
pub 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.
pub 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.
pub 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.
pub 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.
pub 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.
pub 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 "".
pub fn segment_count(self) -> usize
pub fn segment_count(self) -> usize
Number of path segments. O(n) in the path length.
pub 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.
pub 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.
pub 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.
pub 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<'_>
§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§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§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 more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a rama_grpc::Request§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy that returns Action::Follow only if self and other return
Action::Follow. Read more§impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
fn rama_try_from(value: T) -> Result<U, <U as RamaTryFrom<T>>::Error>
§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,
§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.
§impl<V, F> ValueFormatter<&V> for F
impl<V, F> ValueFormatter<&V> for F
§fn format_value(writer: impl ValueWriter, value: &&V)
fn format_value(writer: impl ValueWriter, value: &&V)
value to writer§impl<V, F> ValueFormatter<Arc<V>> for F
impl<V, F> ValueFormatter<Arc<V>> for F
§fn format_value(writer: impl ValueWriter, value: &Arc<V>)
fn format_value(writer: impl ValueWriter, value: &Arc<V>)
value to writer§impl<V, F> ValueFormatter<Box<V>> for F
impl<V, F> ValueFormatter<Box<V>> for F
§fn format_value(writer: impl ValueWriter, value: &Box<V>)
fn format_value(writer: impl ValueWriter, value: &Box<V>)
value to writer§impl<V, F> ValueFormatter<Cow<'_, V>> for F
impl<V, F> ValueFormatter<Cow<'_, V>> for F
§fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)
fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)
value to writer§impl<V, F> ValueFormatter<Option<V>> for Fwhere
F: ValueFormatter<V> + ?Sized,
impl<V, F> ValueFormatter<Option<V>> for Fwhere
F: ValueFormatter<V> + ?Sized,
§fn format_value(writer: impl ValueWriter, value: &Option<V>)
fn format_value(writer: impl ValueWriter, value: &Option<V>)
value to writer