Skip to main content

CloseCode

Struct CloseCode 

Source
pub struct CloseCode(pub u16);
Expand description

A close status code.

A newtype rather than an enum because the range 3000–4999 belongs to the application and must survive a round trip unchanged.

Tuple Fields§

§0: u16

Implementations§

Source§

impl CloseCode

Source

pub const NORMAL: CloseCode

Source

pub const GOING_AWAY: CloseCode

Source

pub const PROTOCOL_ERROR: CloseCode

Source

pub const UNSUPPORTED: CloseCode

Source

pub const NO_STATUS: CloseCode

Never sent on the wire: it means “the peer closed without a code”.

Source

pub const ABNORMAL: CloseCode

Never sent on the wire: it means “the connection died”.

Source

pub const INVALID_PAYLOAD: CloseCode

Source

pub const POLICY: CloseCode

Source

pub const TOO_LARGE: CloseCode

Source

pub const INTERNAL_ERROR: CloseCode

Source

pub fn code(self) -> u16

Source

pub fn is_sendable(self) -> bool

Whether this code is one a peer is allowed to put in a close frame.

Two different reasons a code in 1000–1015 may not be sent:

  • 1005, 1006 and 1015 describe how a connection ended locally — no status given, closed abnormally, TLS failed. They exist for an API to report, and a peer putting one on the wire is lying about what happened. Clients do occasionally try.
  • 1004 is reserved (RFC 6455 §7.4.1). It has no meaning, so a peer sending it is sending nothing we can act on. It used to fall inside 1000..=1014 and was accepted and echoed back; the Autobahn TestSuite’s case 7.9.3 caught it.

1012, 1013 and 1014 stay sendable: IANA registered them after the RFC — service restart, try again later, bad gateway.

Trait Implementations§

Source§

impl Clone for CloseCode

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 Copy for CloseCode

Source§

impl Debug for CloseCode

Source§

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

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

impl Eq for CloseCode

Source§

impl PartialEq for CloseCode

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for CloseCode

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