Struct PathAndQuery

struct PathAndQuery { ... }

Represents the path component of a URI

Implementations

impl PathAndQuery

fn from_static(src: &'static str) -> Self

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

# use http::uri::*;
let v = PathAndQuery::from_static("/hello?world");

assert_eq!(v.path(), "/hello");
assert_eq!(v.query(), Some("world"));
fn from_maybe_shared<T>(src: T) -> Result<Self, InvalidUri>
where
    T: AsRef<[u8]> + 'static

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.

fn path(self: &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

# use http::uri::*;

let path_and_query: PathAndQuery = "/hello/world".parse().unwrap();

assert_eq!(path_and_query.path(), "/hello/world");
fn query(self: &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

# use http::uri::*;
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

# use http::uri::*;
let path_and_query: PathAndQuery = "/hello/world".parse().unwrap();

assert!(path_and_query.query().is_none());
fn as_str(self: &Self) -> &str

Returns the path and query as a string component.

Examples

With a query string component

# use http::uri::*;
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

# use http::uri::*;
let path_and_query: PathAndQuery = "/hello/world".parse().unwrap();

assert_eq!(path_and_query.as_str(), "/hello/world");

impl Clone for PathAndQuery

fn clone(self: &Self) -> PathAndQuery

impl Debug for PathAndQuery

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl Display for PathAndQuery

fn fmt(self: &Self, fmt: &mut Formatter<'_>) -> Result

impl Eq for PathAndQuery

impl Freeze for PathAndQuery

impl FromStr for PathAndQuery

fn from_str(s: &str) -> Result<Self, InvalidUri>

impl Hash for PathAndQuery

fn hash<H: hash::Hasher>(self: &Self, state: &mut H)

impl PartialEq for PathAndQuery

fn eq(self: &Self, other: &str) -> bool

impl PartialEq for PathAndQuery

fn eq(self: &Self, other: &PathAndQuery) -> bool

impl PartialEq for PathAndQuery

fn eq(self: &Self, other: &String) -> bool

impl PartialOrd for PathAndQuery

fn partial_cmp(self: &Self, other: &str) -> Option<Ordering>

impl PartialOrd for PathAndQuery

fn partial_cmp(self: &Self, other: &PathAndQuery) -> Option<Ordering>

impl PartialOrd for PathAndQuery

fn partial_cmp(self: &Self, other: &String) -> Option<Ordering>

impl RefUnwindSafe for PathAndQuery

impl Send for PathAndQuery

impl Sync for PathAndQuery

impl TryFrom for PathAndQuery

fn try_from(vec: Vec<u8>) -> Result<Self, <Self as >::Error>

impl TryFrom for PathAndQuery

fn try_from(s: &String) -> Result<Self, <Self as >::Error>

impl TryFrom for PathAndQuery

fn try_from(s: String) -> Result<Self, <Self as >::Error>

impl Unpin for PathAndQuery

impl UnsafeUnpin for PathAndQuery

impl UnwindSafe for PathAndQuery

impl<'a> PartialEq for PathAndQuery

fn eq(self: &Self, other: &&'a str) -> bool

impl<'a> PartialOrd for PathAndQuery

fn partial_cmp(self: &Self, other: &&'a str) -> Option<Ordering>

impl<'a> TryFrom for PathAndQuery

fn try_from(s: &'a str) -> Result<Self, <Self as >::Error>

impl<'a> TryFrom for PathAndQuery

fn try_from(s: &'a [u8]) -> Result<Self, <Self as >::Error>

impl<T> Any for PathAndQuery

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for PathAndQuery

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for PathAndQuery

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for PathAndQuery

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for PathAndQuery

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for PathAndQuery

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T> ToString for PathAndQuery

fn to_string(self: &Self) -> String

impl<T, U> Into for PathAndQuery

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for PathAndQuery

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for PathAndQuery

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>