Skip to main content

Origin

Struct Origin 

Source
#[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

Source

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.
Source

pub const fn scheme(&self) -> &Scheme

Returns a reference to the scheme.

Source

pub const fn authority(&self) -> &Authority

Returns a reference to the authority.

Source

pub fn into_parts(self) -> (Scheme, Authority)

Consumes the origin and returns the scheme and authority.

Source

pub fn port(&self) -> u16

Returns the port of this origin.

This method determines the port based on the same rules as BaseUri::port.

Source

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");
Source

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 Clone for Origin

Source§

fn clone(&self) -> Origin

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Origin

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Origin

Available on crate feature serde only.
Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Origin

Source§

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 From<Origin> for BaseUri

Source§

fn from(origin: Origin) -> Self

Converts an Origin into a BaseUri with a root path (“/”).

This conversion adds a minimal path component to ensure the resulting URI is valid.

Source§

impl FromStr for Origin

Source§

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).

Source§

type Err = ValidationError

The associated error which can be returned from parsing.
Source§

impl Hash for Origin

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Origin

Source§

fn eq(&self, other: &Origin) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Origin

Available on crate feature serde only.
Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Origin

Source§

impl StructuralPartialEq for Origin

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,