Skip to main content

DomainOrigin

Struct DomainOrigin 

Source
pub struct DomainOrigin<'a, 'b> {
    pub scheme: Scheme<'a>,
    pub host: &'b str,
    pub port: Port,
}
Expand description

A tuple origin.

This can be used to make origin validation more convenient.

Fields§

§scheme: Scheme<'a>

The scheme.

§host: &'b str

The host.

§port: Port

The TCP/UDP port.

Implementations§

Source§

impl<'b> DomainOrigin<'_, 'b>

Source

pub const fn new<'c: 'b>(host: &'c str) -> Self

Returns a DomainOrigin with Self::scheme as Scheme::Https, Self::host as host, and Self::port as Port::None.

§Examples
assert_eq!(
    DomainOrigin::new("www.example.com"),
    Origin(Cow::Borrowed("https://www.example.com"))
);
// `DomainOrigin::new` does not allow _any_ port to exist.
assert_ne!(
    DomainOrigin::new("www.example.com"),
    Origin(Cow::Borrowed("https://www.example.com:443"))
);
Source

pub const fn new_ignore_port<'c: 'b>(host: &'c str) -> Self

Returns a DomainOrigin with Self::scheme as Scheme::Https, Self::host as host, and Self::port as Port::Any.

§Examples
// Any port is allowed to exist.
assert_eq!(
    DomainOrigin::new_ignore_port("www.example.com"),
    Origin(Cow::Borrowed("https://www.example.com:1234"))
);
// A port doesn't have to exist at all either.
assert_eq!(
    DomainOrigin::new_ignore_port("www.example.com"),
    Origin(Cow::Borrowed("https://www.example.com"))
);

Trait Implementations§

Source§

impl<'a, 'b> Clone for DomainOrigin<'a, 'b>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a, 'b> Copy for DomainOrigin<'a, 'b>

Source§

impl<'a, 'b> Debug for DomainOrigin<'a, 'b>

Source§

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

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

impl PartialEq<&DomainOrigin<'_, '_>> for Origin<'_>

Source§

fn eq(&self, other: &&DomainOrigin<'_, '_>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<&Origin<'_>> for DomainOrigin<'_, '_>

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<DomainOrigin<'_, '_>> for Origin<'_>

Source§

fn eq(&self, other: &DomainOrigin<'_, '_>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<DomainOrigin<'_, '_>> for &Origin<'_>

Source§

fn eq(&self, other: &DomainOrigin<'_, '_>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<Origin<'_>> for DomainOrigin<'_, '_>

Source§

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

Returns true iff DomainOrigin::scheme, DomainOrigin::host, and DomainOrigin::port are the same after calling DomainOrigin::try_from on other.0.as_str().

Note that Scheme and Port need not be the same variant. For example Scheme::Https and Scheme::Other containing "https" will be treated the same.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<Origin<'_>> for &DomainOrigin<'_, '_>

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<'a: 'b + 'c, 'b, 'c> TryFrom<&'a str> for DomainOrigin<'b, 'c>

Source§

fn try_from(value: &'a str) -> Result<Self, Self::Error>

value is parsed according to the following extended regex:

^([^:]*:\/\/)?[^:]*(:.*)?$

where the [^:]* of the first capturing group is parsed according to Scheme::try_from, and the .* of the second capturing group is parsed according to Port::from_str.

§Errors

Errors iff Scheme::try_from or Port::from_str fail when applicable.

§Examples
assert!(
    DomainOrigin::try_from("https://www.example.com:443").map_or(false, |dom| matches!(
        dom.scheme,
        Scheme::Https
    ) && dom.host
        == "www.example.com"
        && matches!(dom.port, Port::Val(port) if port == 443))
);
// Parsing is done in a case sensitive way.
assert!(DomainOrigin::try_from("Https://www.EXample.com").map_or(
    false,
    |dom| matches!(dom.scheme, Scheme::Other(scheme) if scheme == "Https")
        && dom.host == "www.EXample.com"
        && matches!(dom.port, Port::None)
));
Source§

type Error = DomainOriginParseErr

The type returned in the event of a conversion error.

Auto Trait Implementations§

§

impl<'a, 'b> Freeze for DomainOrigin<'a, 'b>

§

impl<'a, 'b> RefUnwindSafe for DomainOrigin<'a, 'b>

§

impl<'a, 'b> Send for DomainOrigin<'a, 'b>

§

impl<'a, 'b> Sync for DomainOrigin<'a, 'b>

§

impl<'a, 'b> Unpin for DomainOrigin<'a, 'b>

§

impl<'a, 'b> UnsafeUnpin for DomainOrigin<'a, 'b>

§

impl<'a, 'b> UnwindSafe for DomainOrigin<'a, 'b>

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> Same for T

Source§

type Output = T

Should always be Self
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.