pub struct WebsocketStream<T> {
pub id: Option<String>,
/* private fields */
}Fields§
§id: Option<String>Implementations§
Source§impl<T> WebsocketStream<T>where
T: DeserializeOwned + Send + 'static,
impl<T> WebsocketStream<T>where
T: DeserializeOwned + Send + 'static,
Sourcepub fn on_message<F>(self: &Arc<Self>, callback_fn: F)
pub fn on_message<F>(self: &Arc<Self>, callback_fn: F)
Synchronously sets a message callback for the WebSocket stream on the current thread.
§Arguments
callback_fn- A function that will be called with the deserialized message payload
§Panics
Panics if the thread runtime fails to be created or if the thread join fails
§Examples
let stream = Arc::new(WebsocketStream::new());
stream.on_message(|data: MyType| {
// Handle the deserialized message
});
Sourcepub async fn unsubscribe(&self)
pub async fn unsubscribe(&self)
Unsubscribes from the current WebSocket stream and removes the associated callback.
This method performs the following actions:
- Removes the current callback associated with the stream
- Removes the callback from the connection’s stream callbacks
- Asynchronously unsubscribes from the stream using the WebSocket streams base
§Panics
Panics if the stream is not subscribed to
§Notes
- If no callback is present, no action is taken
- Spawns an asynchronous task to handle the unsubscription process
Auto Trait Implementations§
impl<T> !Freeze for WebsocketStream<T>
impl<T> !RefUnwindSafe for WebsocketStream<T>
impl<T> Send for WebsocketStream<T>where
T: Send,
impl<T> Sync for WebsocketStream<T>where
T: Sync,
impl<T> Unpin for WebsocketStream<T>where
T: Unpin,
impl<T> !UnwindSafe for WebsocketStream<T>
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