pub struct PathAndQuery { /* private fields */ }
Expand description
Represents the path component of a URI
Implementations§
§impl PathAndQuery
impl PathAndQuery
pub fn from_static(src: &'static str) -> PathAndQuery
pub fn from_static(src: &'static str) -> PathAndQuery
Convert a PathAndQuery
from a static string.
This function will not perform any copying, however the string is checked to ensure that it is valid.
§Panics
This function panics if the argument is an invalid path and query.
§Examples
let v = PathAndQuery::from_static("/hello?world");
assert_eq!(v.path(), "/hello");
assert_eq!(v.query(), Some("world"));
Attempt to convert a Bytes
buffer to a PathAndQuery
.
This will try to prevent a copy if the type passed is the type used internally, and will copy the data if it is not.
pub fn path(&self) -> &str
pub fn path(&self) -> &str
Returns the path component
The path component is case sensitive.
abc://username:password@example.com:123/path/data?key=value&key2=value2#fragid1
|--------|
|
path
If the URI is *
then the path component is equal to *
.
§Examples
let path_and_query: PathAndQuery = "/hello/world".parse().unwrap();
assert_eq!(path_and_query.path(), "/hello/world");
pub fn query(&self) -> Option<&str>
pub fn query(&self) -> Option<&str>
Returns the query string component
The query component contains non-hierarchical data that, along with data in the path component, serves to identify a resource within the scope of the URI’s scheme and naming authority (if any). The query component is indicated by the first question mark (“?”) character and terminated by a number sign (“#”) character or by the end of the URI.
abc://username:password@example.com:123/path/data?key=value&key2=value2#fragid1
|-------------------|
|
query
§Examples
With a query string component
let path_and_query: PathAndQuery = "/hello/world?key=value&foo=bar".parse().unwrap();
assert_eq!(path_and_query.query(), Some("key=value&foo=bar"));
Without a query string component
let path_and_query: PathAndQuery = "/hello/world".parse().unwrap();
assert!(path_and_query.query().is_none());
pub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns the path and query as a string component.
§Examples
With a query string component
let path_and_query: PathAndQuery = "/hello/world?key=value&foo=bar".parse().unwrap();
assert_eq!(path_and_query.as_str(), "/hello/world?key=value&foo=bar");
Without a query string component
let path_and_query: PathAndQuery = "/hello/world".parse().unwrap();
assert_eq!(path_and_query.as_str(), "/hello/world");
Trait Implementations§
§impl Clone for PathAndQuery
impl Clone for PathAndQuery
§fn clone(&self) -> PathAndQuery
fn clone(&self) -> PathAndQuery
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more§impl Debug for PathAndQuery
impl Debug for PathAndQuery
§impl Display for PathAndQuery
impl Display for PathAndQuery
§impl From<PathAndQuery> for Uri
impl From<PathAndQuery> for Uri
Convert a PathAndQuery
into a Uri
.
§fn from(path_and_query: PathAndQuery) -> Uri
fn from(path_and_query: PathAndQuery) -> Uri
§impl FromStr for PathAndQuery
impl FromStr for PathAndQuery
§type Err = InvalidUri
type Err = InvalidUri
§fn from_str(s: &str) -> Result<PathAndQuery, InvalidUri>
fn from_str(s: &str) -> Result<PathAndQuery, InvalidUri>
s
to return a value of this type. Read more§impl Hash for PathAndQuery
impl Hash for PathAndQuery
§impl<'a> PartialEq<&'a str> for PathAndQuery
impl<'a> PartialEq<&'a str> for PathAndQuery
§impl<'a> PartialEq<PathAndQuery> for &'a str
impl<'a> PartialEq<PathAndQuery> for &'a str
§fn eq(&self, other: &PathAndQuery) -> bool
fn eq(&self, other: &PathAndQuery) -> bool
self
and other
values to be equal, and is used
by ==
.§impl PartialEq<PathAndQuery> for str
impl PartialEq<PathAndQuery> for str
§fn eq(&self, other: &PathAndQuery) -> bool
fn eq(&self, other: &PathAndQuery) -> bool
self
and other
values to be equal, and is used
by ==
.§impl PartialEq<String> for PathAndQuery
impl PartialEq<String> for PathAndQuery
§impl PartialEq<str> for PathAndQuery
impl PartialEq<str> for PathAndQuery
§impl PartialEq for PathAndQuery
impl PartialEq for PathAndQuery
§fn eq(&self, other: &PathAndQuery) -> bool
fn eq(&self, other: &PathAndQuery) -> bool
self
and other
values to be equal, and is used
by ==
.§impl<'a> PartialOrd<&'a str> for PathAndQuery
impl<'a> PartialOrd<&'a str> for PathAndQuery
§fn partial_cmp(&self, other: &&'a str) -> Option<Ordering>
fn partial_cmp(&self, other: &&'a str) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more§impl<'a> PartialOrd<PathAndQuery> for &'a str
impl<'a> PartialOrd<PathAndQuery> for &'a str
§fn partial_cmp(&self, other: &PathAndQuery) -> Option<Ordering>
fn partial_cmp(&self, other: &PathAndQuery) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more§impl PartialOrd<PathAndQuery> for str
impl PartialOrd<PathAndQuery> for str
§fn partial_cmp(&self, other: &PathAndQuery) -> Option<Ordering>
fn partial_cmp(&self, other: &PathAndQuery) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more§impl PartialOrd<String> for PathAndQuery
impl PartialOrd<String> for PathAndQuery
§fn partial_cmp(&self, other: &String) -> Option<Ordering>
fn partial_cmp(&self, other: &String) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more§impl PartialOrd<str> for PathAndQuery
impl PartialOrd<str> for PathAndQuery
§fn partial_cmp(&self, other: &str) -> Option<Ordering>
fn partial_cmp(&self, other: &str) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more§impl PartialOrd for PathAndQuery
impl PartialOrd for PathAndQuery
§fn partial_cmp(&self, other: &PathAndQuery) -> Option<Ordering>
fn partial_cmp(&self, other: &PathAndQuery) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more