pub struct WebSocketRouter { /* private fields */ }Expand description
WebSocket router: build-time registration + runtime lookup.
The build-time API (consumer(), reverse(), find_pending()) is used
by #[url_patterns(mode = ws)] and UnifiedRouter::websocket().
The async API (register_route(), find_route(), etc.) is used at
connection-handling time in reinhardt-websockets.
Implementations§
Source§impl WebSocketRouter
impl WebSocketRouter
Sourcepub fn new() -> WebSocketRouter
pub fn new() -> WebSocketRouter
Creates a new empty router.
Sourcepub fn with_namespace(self, namespace: impl Into<String>) -> WebSocketRouter
pub fn with_namespace(self, namespace: impl Into<String>) -> WebSocketRouter
Set the namespace for this router.
Parallel to ServerRouter::with_namespace, emitted by
#[url_patterns(mode = ws)] to pass the AppLabel::path(...).
WebSocket route paths are absolute today and are not rewritten
with this namespace; the value is stored for parity with other
routers and future use. See reinhardt-web#3829.
Sourcepub fn namespace(&self) -> Option<&str>
pub fn namespace(&self) -> Option<&str>
Returns the namespace set via with_namespace, if any.
Sourcepub fn consumer<C, F>(self, _f: F) -> WebSocketRouterwhere
F: Fn() -> C,
C: WebSocketEndpointInfo + 'static,
pub fn consumer<C, F>(self, _f: F) -> WebSocketRouterwhere
F: Fn() -> C,
C: WebSocketEndpointInfo + 'static,
Register a WebSocket consumer by its factory function.
Parallel to ServerRouter::endpoint(). Path and name are derived
from C’s WebSocketEndpointInfo impl at compile time.
Sourcepub fn find_pending(&self, name: &str) -> Option<&WebSocketRoute>
pub fn find_pending(&self, name: &str) -> Option<&WebSocketRoute>
Find a pending consumer route by name.
Sourcepub fn reverse(&self, name: &str, params: &[(&str, &str)]) -> Option<String>
pub fn reverse(&self, name: &str, params: &[(&str, &str)]) -> Option<String>
Resolve a WebSocket URL by route name, substituting path parameters.
Sourcepub async fn register_route(
&mut self,
route: WebSocketRoute,
) -> Result<(), RouteError>
pub async fn register_route( &mut self, route: WebSocketRoute, ) -> Result<(), RouteError>
Register a route at runtime (async, used by the connection handler).
Sourcepub async fn find_route(&self, path: &str) -> Option<WebSocketRoute>
pub async fn find_route(&self, path: &str) -> Option<WebSocketRoute>
Looks up a registered route by its exact path.
Sourcepub async fn find_route_by_name(&self, name: &str) -> Option<WebSocketRoute>
pub async fn find_route_by_name(&self, name: &str) -> Option<WebSocketRoute>
Looks up a registered route by its name.
Sourcepub async fn remove_route(&mut self, path: &str) -> Result<(), RouteError>
pub async fn remove_route(&mut self, path: &str) -> Result<(), RouteError>
Removes the registered route for the given path.
Sourcepub async fn all_routes(&self) -> Vec<WebSocketRoute>
pub async fn all_routes(&self) -> Vec<WebSocketRoute>
Returns all currently registered routes.
Sourcepub async fn has_route(&self, path: &str) -> bool
pub async fn has_route(&self, path: &str) -> bool
Returns true if a route is registered for the given path.
Sourcepub async fn route_count(&self) -> usize
pub async fn route_count(&self) -> usize
Returns the number of currently registered routes.
Trait Implementations§
Source§impl Clone for WebSocketRouter
impl Clone for WebSocketRouter
Source§fn clone(&self) -> WebSocketRouter
fn clone(&self) -> WebSocketRouter
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Default for WebSocketRouter
impl Default for WebSocketRouter
Source§fn default() -> WebSocketRouter
fn default() -> WebSocketRouter
Auto Trait Implementations§
impl Freeze for WebSocketRouter
impl !RefUnwindSafe for WebSocketRouter
impl Send for WebSocketRouter
impl Sync for WebSocketRouter
impl Unpin for WebSocketRouter
impl UnsafeUnpin for WebSocketRouter
impl !UnwindSafe for WebSocketRouter
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().