pub struct WebSocket { /* private fields */ }Expand description
A high-level, elegant wrapper for Axum WebSockets, built for premium DX and HTMX
Implementations§
Source§impl WebSocket
impl WebSocket
Sourcepub fn new(inner: AxumWebSocket) -> Self
pub fn new(inner: AxumWebSocket) -> Self
Wraps a raw Axum WebSocket connection in the high-level WebSocket interface.
Sourcepub async fn send_text(
&mut self,
text: impl Into<String>,
) -> Result<(), WsError>
pub async fn send_text( &mut self, text: impl Into<String>, ) -> Result<(), WsError>
Send a text message to the WebSocket client
Sourcepub async fn send_html(&mut self, html_content: String) -> Result<(), WsError>
pub async fn send_html(&mut self, html_content: String) -> Result<(), WsError>
Send an HTML fragment to the client (perfect for out-of-band HTMX swapping)
Sourcepub async fn recv(&mut self) -> Option<Result<String, WsError>>
pub async fn recv(&mut self) -> Option<Result<String, WsError>>
Receive the next text/binary frame from the client.
Ping and Pong control frames are skipped (the underlying socket already
answers pings), so client keepalives never surface as errors. A Close
frame or the end of the stream returns None.
Auto Trait Implementations§
impl !Freeze for WebSocket
impl !RefUnwindSafe for WebSocket
impl !Sync for WebSocket
impl !UnwindSafe for WebSocket
impl Send for WebSocket
impl Unpin for WebSocket
impl UnsafeUnpin for WebSocket
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