#[non_exhaustive]pub struct Address {
pub host: Host,
pub scheme: Scheme,
pub port: Option<u16>,
}Expand description
§HTTP Address
Describes the access address of an HTTP server, including host, scheme, and port.
let host = Host::parse("example.com").expect("valid host");
let address = Address::builder(|addr|{
addr.scheme(Scheme::Https)
.host(host)
.port(8080);
});
assert_eq!(address.host.to_string(), "example.com");
assert_eq!(address.scheme, Scheme::Https);
assert_eq!(address.port, Some(8080));
assert_eq!(address.build_url().as_str(), "https://example.com:8080/");Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.host: Host§scheme: Scheme§port: Option<u16>Implementations§
Source§impl Address
impl Address
Sourcepub fn parse(url: &str) -> Result<Self, Error>
pub fn parse(url: &str) -> Result<Self, Error>
§Parse from URL
let address = Address::parse("https://example.com:8080")?;
assert_eq!(address.host.to_string(), "example.com");
assert_eq!(address.scheme, Scheme::Https);
assert_eq!(address.port, Some(8080));Sourcepub fn build_url(&self) -> Url
pub fn build_url(&self) -> Url
§Build URL
let host = Host::parse("example.com").expect("valid host");
let address = Address::builder(|addr|{
addr.scheme(Scheme::Https)
.host(host)
.port(8080);
});
assert_eq!(address.build_url().as_str(), "https://example.com:8080/");Sourcepub fn from_url(url: &Url) -> Self
pub fn from_url(url: &Url) -> Self
§From URL
let url = "https://example.com:8080".parse::<url::Url>().expect("valid URL");
let address = Address::from_url(&url);
assert_eq!(address.host.to_string(), "example.com");
assert_eq!(address.scheme, Scheme::Https);
assert_eq!(address.port, Some(8080));Sourcepub fn builder<F>(builder_fn: F) -> Selfwhere
F: FnOnce(&mut AddressBuilder<'_>),
pub fn builder<F>(builder_fn: F) -> Selfwhere
F: FnOnce(&mut AddressBuilder<'_>),
§Build Address
let host = Host::parse("127.0.0.1").expect("valid host");
let address = Address::builder(|addr|{
addr.scheme(Scheme::Https)
.host(host)
.port(8080);
});
assert_eq!(address.host.to_string(), "127.0.0.1");
assert_eq!(address.scheme, Scheme::Https);
assert_eq!(address.port, Some(8080));Trait Implementations§
impl Eq for Address
impl StructuralPartialEq for Address
Auto Trait Implementations§
impl Freeze for Address
impl RefUnwindSafe for Address
impl Send for Address
impl Sync for Address
impl Unpin for Address
impl UnsafeUnpin for Address
impl UnwindSafe for Address
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
Mutably borrows from an owned value. Read more