Struct tauri::http::Uri
x3A;:Uri,
pub struct Uri { /* fields omitted */ }
Expand description
The URI component of a request.
For HTTP 1, this is included as part of the request line. From Section 5.3, Request Target:
Once an inbound connection is obtained, the client sends an HTTP request message (Section 3) with a request-target derived from the target URI. There are four distinct formats for the request-target, depending on both the method being requested and whether the request is to a proxy.
```rs request-target = origin-form / absolute-form / authority-form / asterisk-form ```
The URI is structured as follows:
```rs
abc://username:password@example.com:123/path/data?key=value&key2=value2#fragid1
|-| |-------------------------------||--------| |-------------------| |-----|
| | | | |
scheme authority path query fragment
```
For HTTP 2.0, the URI is encoded using pseudoheaders.
#
Examplesuse http::Uri;
let uri = "/foo/bar?baz".parse::<Uri>().unwrap();
assert_eq!(uri.path(), "/foo/bar");
assert_eq!(uri.query(), Some("baz"));
assert_eq!(uri.host(), None);
let uri = "https://www.rust-lang.org/install.html".parse::<Uri>().unwrap();
assert_eq!(uri.scheme_str(), Some("https"));
assert_eq!(uri.host(), Some("www.rust-lang.org"));
assert_eq!(uri.path(), "/install.html");
#
ImplementationsUri[src]#
implbuilder() -> Builder[src]#
pub fnCreates a new builder-style object to manufacture a Uri
.
This method returns an instance of Builder
which can be usd to create a Uri
.
#
Examplesuse http::Uri;
let uri = Uri::builder()
.scheme("https")
.authority("hyper.rs")
.path_and_query("/")
.build()
.unwrap();
from_parts(src: Parts) -> Result<Uri, InvalidUriParts>[src]#
pub fnAttempt to convert a Uri
from Parts
from_maybe_shared<T>(src: T) -> Result<Uri, InvalidUri> where T: AsRef<[u8]> + 'static,[src]#
pub fnAttempt to convert a Bytes
buffer to a Uri
.
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.
from_static(src: &'static str) -> Uri[src]#
pub fnConvert a Uri
from a static string.
This function will not perform any copying, however the string is checked to ensure that it is valid.
#
PanicsThis function panics if the argument is an invalid URI.
#
Exampleslet uri = Uri::from_static("http://example.com/foo");
assert_eq!(uri.host().unwrap(), "example.com");
assert_eq!(uri.path(), "/foo");
into_parts(self) -> Parts[src]#
pub fnConvert a Uri
into Parts
.
#
NoteThis is just an inherent method providing the same functionality as let parts: Parts = uri.into()
#
Exampleslet uri: Uri = "/foo".parse().unwrap();
let parts = uri.into_parts();
assert_eq!(parts.path_and_query.unwrap(), "/foo");
assert!(parts.scheme.is_none());
assert!(parts.authority.is_none());
path_and_query(&self) -> Option<&PathAndQuery>[src]#
pub fnReturns the path & query components of the Uri
path(&self) -> &str[src]#
pub fnGet the path of this Uri
.
Both relative and absolute URIs contain a path component, though it might be the empty string. The path component is case sensitive.
```rs
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 *
.
#
ExamplesA relative URI
let uri: Uri = "/hello/world".parse().unwrap();
assert_eq!(uri.path(), "/hello/world");
An absolute URI
let uri: Uri = "http://example.org/hello/world".parse().unwrap();
assert_eq!(uri.path(), "/hello/world");
scheme(&self) -> Option<&Scheme>[src]#
pub fnGet the scheme of this Uri
.
The URI scheme refers to a specification for assigning identifiers within that scheme. Only absolute URIs contain a scheme component, but not all absolute URIs will contain a scheme component. Although scheme names are case-insensitive, the canonical form is lowercase.
```rs
abc://username:password@example.com:123/path/data?key=value&key2=value2#fragid1
|-|
|
scheme
```
#
ExamplesAbsolute URI
use http::uri::{Scheme, Uri};
let uri: Uri = "http://example.org/hello/world".parse().unwrap();
assert_eq!(uri.scheme(), Some(&Scheme::HTTP));
Relative URI
let uri: Uri = "/hello/world".parse().unwrap();
assert!(uri.scheme().is_none());
scheme_str(&self) -> Option<&str>[src]#
pub fnGet the scheme of this Uri
as a &str
.
#
Examplelet uri: Uri = "http://example.org/hello/world".parse().unwrap();
assert_eq!(uri.scheme_str(), Some("http"));
authority(&self) -> Option<&Authority>[src]#
pub fnGet the authority of this Uri
.
The authority is a hierarchical element for naming authority such that the remainder of the URI is delegated to that authority. For HTTP, the authority consists of the host and port. The host portion of the authority is case-insensitive.
The authority also includes a username:password
component, however the use of this is deprecated and should be avoided.
```rs
abc://username:password@example.com:123/path/data?key=value&key2=value2#fragid1
|-------------------------------|
|
authority
```
This function will be renamed to authority
in the next semver release.
#
ExamplesAbsolute URI
let uri: Uri = "http://example.org:80/hello/world".parse().unwrap();
assert_eq!(uri.authority().map(|a| a.as_str()), Some("example.org:80"));
Relative URI
let uri: Uri = "/hello/world".parse().unwrap();
assert!(uri.authority().is_none());
host(&self) -> Option<&str>[src]#
pub fnGet the host of this Uri
.
The host subcomponent of authority is identified by an IP literal encapsulated within square brackets, an IPv4 address in dotted- decimal form, or a registered name. The host subcomponent is case-insensitive.
```rs
abc://username:password@example.com:123/path/data?key=value&key2=value2#fragid1
|---------|
|
host
```
#
ExamplesAbsolute URI
let uri: Uri = "http://example.org:80/hello/world".parse().unwrap();
assert_eq!(uri.host(), Some("example.org"));
Relative URI
let uri: Uri = "/hello/world".parse().unwrap();
assert!(uri.host().is_none());
port(&self) -> Option<Port<&str>>[src]#
pub fnGet the port part of this Uri
.
The port subcomponent of authority is designated by an optional port number following the host and delimited from it by a single colon (“:”) character. It can be turned into a decimal port number with the as_u16
method or as a str
with the as_str
method.
```rs
abc://username:password@example.com:123/path/data?key=value&key2=value2#fragid1
|-|
|
port
```
#
ExamplesAbsolute URI with port
let uri: Uri = "http://example.org:80/hello/world".parse().unwrap();
let port = uri.port().unwrap();
assert_eq!(port.as_u16(), 80);
Absolute URI without port
let uri: Uri = "http://example.org/hello/world".parse().unwrap();
assert!(uri.port().is_none());
Relative URI
let uri: Uri = "/hello/world".parse().unwrap();
assert!(uri.port().is_none());
port_u16(&self) -> Option<u16>[src]#
pub fnGet the port of this Uri
as a u16
.
#
Examplelet uri: Uri = "http://example.org:80/hello/world".parse().unwrap();
assert_eq!(uri.port_u16(), Some(80));
query(&self) -> Option<&str>[src]#
pub fnGet the query string of this Uri
, starting after the ?
.
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.
```rs
abc://username:password@example.com:123/path/data?key=value&key2=value2#fragid1
|-------------------|
|
query
```
#
ExamplesAbsolute URI
let uri: Uri = "http://example.org/hello/world?key=value".parse().unwrap();
assert_eq!(uri.query(), Some("key=value"));
Relative URI with a query string component
let uri: Uri = "/hello/world?key=value&foo=bar".parse().unwrap();
assert_eq!(uri.query(), Some("key=value&foo=bar"));
Relative URI without a query string component
let uri: Uri = "/hello/world".parse().unwrap();
assert!(uri.query().is_none());
#
Trait ImplementationsClone for Uri[src]#
implclone(&self) -> Uri[src]#
pub fnReturns a copy of the value. Read more
clone_from(&mut self, source: &Self)1.0.0[src]#
fnPerforms copy-assignment from source
. Read more
Debug for Uri[src]#
implfmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>[src]#
pub fnFormats the value using the given formatter. Read more
Default for Uri[src]#
implReturns a Uri
representing /
default() -> Uri[src]#
pub fnReturns the “default value” for a type. Read more
Display for Uri[src]#
implfmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>[src]#
pub fnFormats the value using the given formatter. Read more
FromStr for Uri[src]#
implErr = InvalidUri#
typeThe associated error which can be returned from parsing.
from_str(s: &str) -> Result<Uri, InvalidUri>[src]#
pub fnParses a string s
to return a value of this type. Read more
Hash for Uri[src]#
implhash<H>(&self, state: &mutH) where H: Hasher,[src]#
pub fnFeeds this value into the given Hasher
. Read more
hash_slice<H>(data: &[Self], state: &mutH) where H: Hasher,1.3.0[src]#
fnFeeds a slice of this type into the given Hasher
. Read more
PartialEq<<'a str> for Uri[src]#
impl<'a>eq(&self, other: &&'a str) -> bool[src]#
pub fnThis method tests for self
and other
values to be equal, and is used by ==
. Read more
ne(&self, other: &Rhs) -> bool1.0.0[src]#
#[must_use]fnThis method tests for !=
.
PartialEq<Uri> for Uri[src]#
impleq(&self, other: &Uri) -> bool[src]#
pub fnThis method tests for self
and other
values to be equal, and is used by ==
. Read more
ne(&self, other: &Rhs) -> bool1.0.0[src]#
#[must_use]fnThis method tests for !=
.
PartialEq<str> for Uri[src]#
impleq(&self, other: &str) -> bool[src]#
pub fnThis method tests for self
and other
values to be equal, and is used by ==
. Read more
ne(&self, other: &Rhs) -> bool1.0.0[src]#
#[must_use]fnThis method tests for !=
.
TryFrom<&'a [u8]> for Uri[src]#
impl<'a>Error = InvalidUri#
typeThe type returned in the event of a conversion error.
try_from(t: &'a [u8]) -> Result<Uri, <Uri as TryFrom<&'a [u8]>>::Error>[src]#
pub fnPerforms the conversion.
TryFrom<<'a String> for Uri[src]#
impl<'a>Error = InvalidUri#
typeThe type returned in the event of a conversion error.
try_from( t: &'a String ) -> Result<Uri, <Uri as TryFrom<<'a String>>::Error>[src]#
pub fnPerforms the conversion.
TryFrom<<'a Uri> for Uri[src]#
impl<'a>Error = Error#
typeThe type returned in the event of a conversion error.
try_from(src: &'a Uri) -> Result<Uri, <Uri as TryFrom<<'a Uri>>::Error>[src]#
pub fnPerforms the conversion.
TryFrom<<'a str> for Uri[src]#
impl<'a>Error = InvalidUri#
typeThe type returned in the event of a conversion error.
try_from(t: &'a str) -> Result<Uri, <Uri as TryFrom<<'a str>>::Error>[src]#
pub fnPerforms the conversion.
TryFrom<Parts> for Uri[src]#
implError = InvalidUriParts#
typeThe type returned in the event of a conversion error.
try_from(src: Parts) -> Result<Uri, <Uri as TryFrom<Parts>>::Error>[src]#
pub fnPerforms the conversion.
TryFrom<String> for Uri[src]#
implError = InvalidUri#
typeThe type returned in the event of a conversion error.
try_from(t: String) -> Result<Uri, <Uri as TryFrom<String>>::Error>[src]#
pub fnPerforms the conversion.
Eq for Uri#
impl#
Auto Trait ImplementationsRefUnwindSafe for Uri#
implSend for Uri#
implSync for Uri#
implUnpin for Uri#
implUnwindSafe for Uri#
impl#
Blanket ImplementationsAny for T where T: 'static + ?Sized,[src]#
impl<T>type_id(&self) -> TypeId[src]#
pub fnGets the TypeId
of self
. Read more
Borrow<T> for T where T: ?Sized,[src]#
impl<T>borrow(&self) -> &T[src]#
pub fnImmutably borrows from an owned value. Read more
BorrowMut<T> for T where T: ?Sized,[src]#
impl<T>borrow_mut(&mut self) -> &mutT[src]#
pub fnMutably borrows from an owned value. Read more
From<T> for T[src]#
impl<T>from(t: T) -> T[src]#
pub fnPerforms the conversion.
Into<U> for T where U: From<T>,[src]#
impl<T, U>into(self) -> U[src]#
pub fnPerforms the conversion.
ToOwned for T where T: Clone,[src]#
impl<T>Owned = T#
typeThe resulting type after obtaining ownership.
to_owned(&self) -> T[src]#
pub fnCreates owned data from borrowed data, usually by cloning. Read more
clone_into(&self, target: &mutT)[src]#
pub fn🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
ToString for T where T: Display + ?Sized,[src]#
impl<T>to_string(&self) -> String[src]#
pub default fnConverts the given value to a String
. Read more
TryFrom<U> for T where U: Into<T>,[src]#
impl<T, U>Error = Infallible#
typeThe type returned in the event of a conversion error.
try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]#
pub fnPerforms the conversion.
TryInto<U> for T where U: TryFrom<T>,[src]#
impl<T, U>Error = <U as TryFrom<T>>::Error#
typeThe type returned in the event of a conversion error.
try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]#
pub fnPerforms the conversion.