pub struct Origin<'a> {
pub scheme: &'a [u8],
pub host: Host<'a>,
pub port: Option<u16>,
}Expand description
A serialized origin.
Fields§
§scheme: &'a [u8]The scheme as sent (compare it ASCII case-insensitively).
host: Host<'a>The host.
port: Option<u16>The port, when one was given.
Implementations§
Source§impl Origin<'_>
impl Origin<'_>
Sourcepub fn effective_port(&self) -> Option<u16>
pub fn effective_port(&self) -> Option<u16>
The port, or the scheme’s default: 80 for http and ws, 443 for
https and wss; None for another scheme without a port.
§Examples
use parse_net::{parse_origin, OriginValue};
let OriginValue::Origin(o) = parse_origin(b"wss://chat.example")? else { unreachable!() };
assert_eq!(o.effective_port(), Some(443));Sourcepub fn same_origin(&self, other: &Origin<'_>) -> bool
pub fn same_origin(&self, other: &Origin<'_>) -> bool
Whether two origins are the same: schemes and hosts equal as whole values (ASCII case-insensitive, IP literals by value), effective ports equal. Never a prefix or suffix comparison.
Sourcepub fn write_to(&self, out: &mut impl Sink) -> Result<(), WriteError>
pub fn write_to(&self, out: &mut impl Sink) -> Result<(), WriteError>
Writes the origin with a lowercase scheme and without a default port.
§Errors
WriteError::Full; nothing is written when the sink reports its
room.
§Examples
use parse_net::{parse_origin, OriginValue, SliceSink};
let OriginValue::Origin(o) = parse_origin(b"HTTPS://a.example:443")? else { unreachable!() };
let mut buf = [0u8; 64];
let mut out = SliceSink::new(&mut buf);
o.write_to(&mut out).expect("room");
assert_eq!(out.written(), b"https://a.example");Trait Implementations§
impl<'a> Copy for Origin<'a>
impl<'a> Eq for Origin<'a>
impl<'a> StructuralPartialEq for Origin<'a>
Auto Trait Implementations§
impl<'a> Freeze for Origin<'a>
impl<'a> RefUnwindSafe for Origin<'a>
impl<'a> Send for Origin<'a>
impl<'a> Sync for Origin<'a>
impl<'a> Unpin for Origin<'a>
impl<'a> UnsafeUnpin for Origin<'a>
impl<'a> UnwindSafe for Origin<'a>
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