pub struct OptimizedMessageHandler<F> { /* private fields */ }Available on crate feature
websocket only.Expand description
Optimized handler that processes individual messages with automatic loop.
This handler type automatically manages the message receive loop and calls your function for each incoming message until the connection closes.
§Example
use ignitia::prelude::*;
let handler = websocket_message_handler(|ws: WebSocketConnection, msg: Message| async move {
match msg {
Message::Text(text) => {
ws.send_text(format!("Received: {}", text)).await.ok();
Response::ok()
}
Message::Binary(data) => {
ws.send_binary(data).await.ok();
Response::ok()
}
_ => Response::ok()
}
});
router.websocket("/ws/messages", handler);Implementations§
Source§impl<F> OptimizedMessageHandler<F>
impl<F> OptimizedMessageHandler<F>
Trait Implementations§
Source§impl<F> Clone for OptimizedMessageHandler<F>
impl<F> Clone for OptimizedMessageHandler<F>
Source§impl<F, Fut, R> UniversalWebSocketHandler<()> for OptimizedMessageHandler<F>where
F: Fn(WebSocketConnection, Message) -> Fut + Send + Sync + 'static,
Fut: Future<Output = R> + Send + 'static,
R: IntoResponse,
impl<F, Fut, R> UniversalWebSocketHandler<()> for OptimizedMessageHandler<F>where
F: Fn(WebSocketConnection, Message) -> Fut + Send + Sync + 'static,
Fut: Future<Output = R> + Send + 'static,
R: IntoResponse,
Auto Trait Implementations§
impl<F> Freeze for OptimizedMessageHandler<F>
impl<F> RefUnwindSafe for OptimizedMessageHandler<F>where
F: RefUnwindSafe,
impl<F> Send for OptimizedMessageHandler<F>
impl<F> Sync for OptimizedMessageHandler<F>
impl<F> Unpin for OptimizedMessageHandler<F>
impl<F> UnwindSafe for OptimizedMessageHandler<F>where
F: RefUnwindSafe,
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