pub struct UrlPath { /* private fields */ }
Expand description
Represent the path portion of a URL (including any query string)
Implementations§
source§impl UrlPath
impl UrlPath
sourcepub fn new(path: &str) -> Self
pub fn new(path: &str) -> Self
Create a new UrlPath
path
should have any special characters percent escaped.
Any leading '/'
s are removed.
sourcepub fn path(&self) -> &str
pub fn path(&self) -> &str
Get the path portion of the UrlPath
assert_eq!(UrlPath::new("path?query_string").path(), "path");
assert_eq!(UrlPath::new("?query_string").path(), "");
assert_eq!(UrlPath::new("?").path(), "");
assert_eq!(UrlPath::new("").path(), "");
sourcepub fn path_components(&self) -> impl Iterator<Item = &str>
pub fn path_components(&self) -> impl Iterator<Item = &str>
Get the path components of the UrlPath
let path = UrlPath::new("path1/path2/path3");
let components: Vec<&str> = path.path_components().collect();
assert_eq!(&components, &["path1", "path2", "path3"]);
let path = UrlPath::new("");
assert_eq!(path.path_components().next(), None);
let path = UrlPath::new("path1//path2"); // Note the double `'/'`
let components: Vec<&str> = path.path_components().collect();
assert_eq!(&components, &["path1", "", "path2"]);
sourcepub fn path_components_vec(&self) -> Vec<&str>
pub fn path_components_vec(&self) -> Vec<&str>
As UrlPath::path_components
but collected into a Vec
sourcepub fn query_string(&self) -> &str
pub fn query_string(&self) -> &str
Get the query string portion of the UrlPath
assert_eq!(
UrlPath::new("path?query_string").query_string(),
"query_string"
);
assert_eq!(UrlPath::new("?query_string").query_string(), "query_string");
assert_eq!(UrlPath::new("?").query_string(), "");
assert_eq!(UrlPath::new("").query_string(), "");
assert_eq!(UrlPath::new("#hash").query_string(), "");
assert_eq!(
UrlPath::new("?query_string#hash").query_string(),
"query_string"
);
sourcepub fn query(&self) -> impl Iterator<Item = (&str, Option<&str>)>
pub fn query(&self) -> impl Iterator<Item = (&str, Option<&str>)>
Split the query string into key/value pairs
let path = UrlPath::new("path?x=1&y=2&flag");
let kv_args: Vec<(&str, Option<&str>)> = path.query().collect();
assert_eq!(
&kv_args,
&[("x", Some("1")), ("y", Some("2")), ("flag", None)]
);
sourcepub fn query_map(&self) -> HashMap<&str, Option<&str>>
pub fn query_map(&self) -> HashMap<&str, Option<&str>>
As UrlPath::query
but collected into a HashMap
Trait Implementations§
source§impl PartialEq for UrlPath
impl PartialEq for UrlPath
impl Eq for UrlPath
impl StructuralPartialEq for UrlPath
Auto Trait Implementations§
impl Freeze for UrlPath
impl RefUnwindSafe for UrlPath
impl Send for UrlPath
impl Sync for UrlPath
impl Unpin for UrlPath
impl UnwindSafe for UrlPath
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
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<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
Compare self to
key
and return true
if they are equal.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>
Converts
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>
Converts
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