pub enum UriKey {
Path(CompactString),
PathQuery(PathQuery),
}
Expand description
A key for an Uri used in ResponseCache
.
This is, for now, an opaque type in it’s API. Though, you can extract the path and query through matching.
Variants§
Path(CompactString)
Uri with only a path component.
Searching the cache with this should be avoided.
See Self::call_all
.
PathQuery(PathQuery)
Uri with a path and optional query.
See PathQuery
.
Implementations§
source§impl UriKey
impl UriKey
sourcepub fn path_and_query(uri: &Uri) -> Self
pub fn path_and_query(uri: &Uri) -> Self
Constructs a new UriKey
from uri
.
This variant will math both Self::PathQuery
and Self::Path
if Self::call_all
is called on it.
sourcepub fn call_all<T>(
self,
callback: impl FnMut(&Self) -> Option<T>
) -> (Self, Option<T>)
pub fn call_all<T>( self, callback: impl FnMut(&Self) -> Option<T> ) -> (Self, Option<T>)
Tries to get type T
from callback
using current variant and other variants with fewer data.
Returns Self
which got a result from callback
or, if none, truncated to Self::Path
.
§Examples
use kvarn::prelude::*;
let key = UriKey::path_and_query(&Uri::from_static("https://icelk.dev/status?format=json"));
// First gets called once with key as UriKey::PathQuery("/status?format=json")
// then, the query gets truncated and we get a key as UriKey::Path("/status").
let (_key, found) = key.call_all(|key| {
match key {
UriKey::Path(path) if *path == "/status" => Some(true),
_ => None
}
});
assert_eq!(found, Some(true));
Trait Implementations§
source§impl PartialEq for UriKey
impl PartialEq for UriKey
impl Eq for UriKey
impl StructuralPartialEq for UriKey
Auto Trait Implementations§
impl Freeze for UriKey
impl RefUnwindSafe for UriKey
impl Send for UriKey
impl Sync for UriKey
impl Unpin for UriKey
impl UnwindSafe for UriKey
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
§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
Checks if this value is equivalent to the given key. Read more
§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
Compare self to
key
and return true
if they are equal.