Struct problem_details::ProblemType
source · pub struct ProblemType(/* private fields */);
Expand description
A type that represents a problem type URI.
This type is mostly a wrapper around http::Uri
. It implements
std::default::Default
to return about:blank
as the default problem type.
Creating a problem type
You should rarely need to create a ProblemType
manually. Instead, you can
just create an Uri
and pass that e.g. to ProblemDetails::with_type
.
In case you do need to create a ProblemType
manually, you can use
the From
trait to convert a given Uri
,
or Default::default()
to create a default URI.
use http::Uri;
use problem_details::ProblemType;
// Create a problem type from a URI
let uri = Uri::from_static("https://example.com/problem");
let problem_type = ProblemType::from(uri);
assert_eq!(problem_type.to_string(), "https://example.com/problem");
// Create a default problem type
let default_type = ProblemType::default();
assert_eq!(default_type.to_string(), "about:blank");
Methods from Deref<Target = Uri>§
sourcepub fn path_and_query(&self) -> Option<&PathAndQuery>
pub fn path_and_query(&self) -> Option<&PathAndQuery>
Returns the path & query components of the Uri
sourcepub fn path(&self) -> &str
pub fn path(&self) -> &str
Get 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.
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
A 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");
sourcepub fn scheme(&self) -> Option<&Scheme>
pub fn scheme(&self) -> Option<&Scheme>
Get 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.
abc://username:password@example.com:123/path/data?key=value&key2=value2#fragid1
|-|
|
scheme
Examples
Absolute 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());
sourcepub fn scheme_str(&self) -> Option<&str>
pub fn scheme_str(&self) -> Option<&str>
Get the scheme of this Uri
as a &str
.
Example
let uri: Uri = "http://example.org/hello/world".parse().unwrap();
assert_eq!(uri.scheme_str(), Some("http"));
Get 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.
abc://username:password@example.com:123/path/data?key=value&key2=value2#fragid1
|-------------------------------|
|
authority
Examples
Absolute 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());
sourcepub fn host(&self) -> Option<&str>
pub fn host(&self) -> Option<&str>
Get 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.
abc://username:password@example.com:123/path/data?key=value&key2=value2#fragid1
|---------|
|
host
Examples
Absolute 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());
sourcepub fn port(&self) -> Option<Port<&str>>
pub fn port(&self) -> Option<Port<&str>>
Get 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.
abc://username:password@example.com:123/path/data?key=value&key2=value2#fragid1
|-|
|
port
Examples
Absolute 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());
sourcepub fn port_u16(&self) -> Option<u16>
pub fn port_u16(&self) -> Option<u16>
Get the port of this Uri
as a u16
.
Example
let uri: Uri = "http://example.org:80/hello/world".parse().unwrap();
assert_eq!(uri.port_u16(), Some(80));
sourcepub fn query(&self) -> Option<&str>
pub fn query(&self) -> Option<&str>
Get 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.
abc://username:password@example.com:123/path/data?key=value&key2=value2#fragid1
|-------------------|
|
query
Examples
Absolute 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 Implementations§
source§impl AsMut<Uri> for ProblemType
impl AsMut<Uri> for ProblemType
source§impl AsRef<Uri> for ProblemType
impl AsRef<Uri> for ProblemType
source§impl Borrow<Uri> for ProblemType
impl Borrow<Uri> for ProblemType
source§impl BorrowMut<Uri> for ProblemType
impl BorrowMut<Uri> for ProblemType
source§fn borrow_mut(&mut self) -> &mut Uri
fn borrow_mut(&mut self) -> &mut Uri
source§impl Clone for ProblemType
impl Clone for ProblemType
source§fn clone(&self) -> ProblemType
fn clone(&self) -> ProblemType
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for ProblemType
impl Debug for ProblemType
source§impl Default for ProblemType
impl Default for ProblemType
source§impl Deref for ProblemType
impl Deref for ProblemType
source§impl DerefMut for ProblemType
impl DerefMut for ProblemType
source§impl<'de> Deserialize<'de> for ProblemType
impl<'de> Deserialize<'de> for ProblemType
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl Display for ProblemType
impl Display for ProblemType
source§impl From<ProblemType> for Uri
impl From<ProblemType> for Uri
source§fn from(value: ProblemType) -> Self
fn from(value: ProblemType) -> Self
source§impl From<Uri> for ProblemType
impl From<Uri> for ProblemType
source§impl PartialEq for ProblemType
impl PartialEq for ProblemType
source§fn eq(&self, other: &ProblemType) -> bool
fn eq(&self, other: &ProblemType) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl Serialize for ProblemType
impl Serialize for ProblemType
impl Eq for ProblemType
impl StructuralEq for ProblemType
impl StructuralPartialEq for ProblemType
Auto Trait Implementations§
impl RefUnwindSafe for ProblemType
impl Send for ProblemType
impl Sync for ProblemType
impl Unpin for ProblemType
impl UnwindSafe for ProblemType
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
§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
§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
key
and return true
if they are equal.