Skip to main content

WscallServer

Struct WscallServer 

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

Main server type used to register routes, filters, and event handlers.

Implementations§

Source§

impl WscallServer

Source

pub fn new() -> Self

Source

pub fn with_ecdh(self) -> Self

Enables ECDH dynamic key agreement.

Instead of a pre-shared symmetric key, each connection performs an X25519 handshake right after the WebSocket upgrade. The negotiated 32-byte session key is used with ChaCha20-Poly1305 for all subsequent frames. This is mutually exclusive with with_chacha20_key / with_aes256_key.

Source

pub fn with_chacha20_key(self, key: [u8; 32]) -> Self

Source

pub fn with_aes256_key(self, key: [u8; 32]) -> Self

Source

pub fn with_max_connections(self, max: usize) -> Self

Caps the number of concurrently accepted connections.

When the cap is reached, new accept calls block until an existing connection drops, providing natural backpressure against connection flooding instead of spawning unbounded tasks.

Source

pub fn with_max_in_flight(self, max: usize) -> Self

Caps the number of concurrently in-flight request/event handlers per single connection, bounding per-connection CPU and memory usage.

Source

pub fn with_max_frame_bytes(self, max: usize) -> Self

Sets the maximum total frame size (including the 4-byte length prefix).

Frames exceeding this limit cause the server to send a 413 error response frame (request_id=0, code="frame_too_large"); the connection stays open. Default: 100 MiB.

Source

pub fn handle(&self) -> ServerHandle

Source

pub fn route<F, Fut>(&mut self, route: impl Into<String>, handler: F)
where F: Fn(ApiContext) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<Value, ApiError>> + Send + 'static,

Source

pub fn typed_route<T, F, Fut>(&mut self, route: impl Into<String>, handler: F)
where T: DeserializeOwned + Send + 'static, F: Fn(ApiContext, T) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<Value, ApiError>> + Send + 'static,

Source

pub fn validated_route<T, F, Fut>( &mut self, route: impl Into<String>, handler: F, )
where T: DeserializeOwned + Validate + Send + 'static, F: Fn(ApiContext, T) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<Value, ApiError>> + Send + 'static,

Source

pub fn filter<F, Fut>(&mut self, filter: F)
where F: Fn(ApiContext) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<ApiContext, ApiError>> + Send + 'static,

Source

pub fn event_handler<F, Fut>(&mut self, name: impl Into<String>, handler: F)
where F: Fn(EventContext) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<Value, ApiError>> + Send + 'static,

Source

pub fn on_connected<F, Fut>(&mut self, handler: F)
where F: Fn(ServerConnectionContext) -> Fut + Send + Sync + 'static, Fut: Future<Output = ()> + Send + 'static,

Source

pub fn on_disconnected<F, Fut>(&mut self, handler: F)
where F: Fn(ServerDisconnectContext) -> Fut + Send + Sync + 'static, Fut: Future<Output = ()> + Send + 'static,

Source

pub fn exception_handler<F, Fut>(&mut self, handler: F)
where F: Fn(ExceptionContext) -> Fut + Send + Sync + 'static, Fut: Future<Output = ErrorPayload> + Send + 'static,

Source

pub async fn listen(self, address: &str) -> Result<(), ServerError>

Trait Implementations§

Source§

impl Default for WscallServer

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more