Skip to main content

WebSocketRoutes

Struct WebSocketRoutes 

Source
pub struct WebSocketRoutes { /* private fields */ }
Expand description

The WebSocket routes an application declares — routes/ws.rs.

Separate from the HTTP router because the two answer different things: an HTTP route returns a response and is done, a socket route starts a conversation. Sharing one table would mean one of them pretending.

ⓘ
pub fn routes() -> WebSocketRoutes {
    WebSocketRoutes::new()
        .add("/ws/rooms/{room}", Chat::new(rooms))
        .add("/ws/notifications", Notifications)
}

Implementations§

Source§

impl WebSocketRoutes

Source

pub fn new() -> Self

No routes. Every upgrade is a 404 until something is declared.

Source

pub fn add( self, pattern: impl Into<String>, handler: impl WebSocketHandler, ) -> Self

Serve handler at pattern.

{name} captures a segment, readable from Socket::param. The first matching pattern wins, so declare the specific before the general.

Source

pub fn add_arc( self, pattern: impl Into<String>, handler: Arc<dyn WebSocketHandler>, ) -> Self

Serve a handler you already share.

Source

pub fn match_path(&self, path: &str) -> Option<Matched>

The handler for path, and whatever its pattern captured.

Source

pub fn patterns(&self) -> Vec<&str>

The declared patterns, for route:list.

Source

pub fn len(&self) -> usize

How many are declared.

Source

pub fn is_empty(&self) -> bool

Whether none are.

Trait Implementations§

Source§

impl Debug for WebSocketRoutes

Source§

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

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

impl Default for WebSocketRoutes

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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