#[non_exhaustive]pub struct Origin { /* private fields */ }Expand description
Represents the origin of a URI, consisting of the scheme and authority components.
This struct is useful for scenarios where you need to work with the base parts of a URI without the path, query, or fragment components.
Implementations§
Source§impl Origin
impl Origin
Sourcepub fn new(
scheme: impl TryInto<Scheme, Error: Into<Error>>,
authority: impl TryInto<Authority, Error: Into<Error>>,
) -> Result<Self, ValidationError>
pub fn new( scheme: impl TryInto<Scheme, Error: Into<Error>>, authority: impl TryInto<Authority, Error: Into<Error>>, ) -> Result<Self, ValidationError>
Creates a new Origin from the given scheme and authority.
§Arguments
scheme: The URI scheme (must be either HTTP or HTTPS).authority: The authority component (hostname and optional port).
§Errors
Returns a validation error if:
- The scheme is not HTTP or HTTPS.
- The scheme or authority conversion fails.
Returns a reference to the authority.
Sourcepub fn into_parts(self) -> (Scheme, Authority)
pub fn into_parts(self) -> (Scheme, Authority)
Consumes the origin and returns the scheme and authority.
Sourcepub fn port(&self) -> u16
pub fn port(&self) -> u16
Returns the port of this origin.
This method determines the port based on the same rules as BaseUri::port.
Sourcepub fn with_port(self, port: u16) -> Self
pub fn with_port(self, port: u16) -> Self
Set port for this Origin instance.
§Examples
let origin = Origin::new("https", "example.com").unwrap();
let origin_with_port = origin.with_port(8443);
assert_eq!(origin_with_port.port(), 8443);
assert_eq!(format!("{}", origin_with_port), "https://example.com:8443");Sourcepub fn is_https(&self) -> bool
pub fn is_https(&self) -> bool
Checks if this origin uses the HTTPS scheme.
This method returns true if the scheme is HTTPS, false otherwise.
For more details, see BaseUri::is_https.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Origin
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Origin
serde only.Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl Display for Origin
impl Display for Origin
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the Origin as a string in the form scheme://authority.
Default ports (80 for HTTP, 443 for HTTPS) are omitted from the display string. Custom ports are included when present.
§Examples
let origin = Origin::new(Scheme::HTTPS, "example.com:443").unwrap();
assert_eq!(format!("{}", origin), "https://example.com");
let custom_port = Origin::new(Scheme::HTTPS, "example.com:8443").unwrap();
assert_eq!(format!("{}", custom_port), "https://example.com:8443");Source§impl FromStr for Origin
impl FromStr for Origin
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
Parses an Origin from a string in the form scheme://authority.
§Errors
Returns a ValidationError if the string is not a valid origin
(missing scheme, unsupported scheme, or invalid authority).