Struct fluent_uri::component::Scheme
source · pub struct Scheme { /* private fields */ }Expand description
The scheme component of URI reference.
§Comparison
Schemes are compared case-insensitively. You should do a case-insensitive
comparison if the scheme specification allows both letter cases in the scheme name.
§Examples
use fluent_uri::{component::Scheme, UriRef};
const SCHEME_HTTP: &Scheme = Scheme::new_or_panic("http");
let uri_ref = UriRef::parse("HTTP://EXAMPLE.COM/")?;
let scheme = uri_ref.scheme().unwrap();
// Case-insensitive comparison.
assert_eq!(scheme, SCHEME_HTTP);
// Case-sensitive comparison.
assert_eq!(scheme.as_str(), "HTTP");Implementations§
source§impl Scheme
impl Scheme
sourcepub const fn new_or_panic(s: &str) -> &Scheme
pub const fn new_or_panic(s: &str) -> &Scheme
Converts a string slice to &Scheme.
§Panics
Panics if the string is not a valid scheme name according to
Section 3.1 of RFC 3986. For a non-panicking variant,
use new.
sourcepub const fn new(s: &str) -> Option<&Scheme>
pub const fn new(s: &str) -> Option<&Scheme>
Converts a string slice to &Scheme, returning None if the conversion fails.
sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns the scheme component as a string slice.
§Examples
use fluent_uri::UriRef;
let uri_ref = UriRef::parse("http://example.com/")?;
assert_eq!(uri_ref.scheme().unwrap().as_str(), "http");
let uri_ref = UriRef::parse("HTTP://EXAMPLE.COM/")?;
assert_eq!(uri_ref.scheme().unwrap().as_str(), "HTTP");