pub struct WebsocketCommands { /* private fields */ }Expand description
A command buffer returned from a websocket callback.
Implementations§
Source§impl WebsocketCommands
impl WebsocketCommands
Sourcepub fn with_send<T: Into<WebsocketMessage>>(message: T) -> Self
pub fn with_send<T: Into<WebsocketMessage>>(message: T) -> Self
Constructs a new websocket command buffer to send message.
Examples found in repository?
examples/server.rs (line 41)
32 async fn websocket_handle(
33 &mut self,
34 message: WebsocketMessage,
35 ) -> Result<Option<WebsocketCommands>, ExitReason> {
36 match message {
37 WebsocketMessage::Text(text) => {
38 tracing::info!(handler = ?Process::current(), message = ?text.as_str(), "Got message");
39
40 // Echo the command back to the client.
41 Ok(Some(WebsocketCommands::with_send(text.as_str())))
42 }
43 _ => {
44 // Hydra websockets automatically responds to ping requests.
45 Ok(None)
46 }
47 }
48 }Sourcepub fn with_close<T: Into<String>>(code: CloseCode, reason: T) -> Self
pub fn with_close<T: Into<String>>(code: CloseCode, reason: T) -> Self
Constructs a new websocket command buffer to close the websocket gracefully.
Sourcepub fn send<T: Into<WebsocketMessage>>(&mut self, message: T)
pub fn send<T: Into<WebsocketMessage>>(&mut self, message: T)
Sends the message to the websocket client.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for WebsocketCommands
impl RefUnwindSafe for WebsocketCommands
impl Send for WebsocketCommands
impl Sync for WebsocketCommands
impl Unpin for WebsocketCommands
impl UnwindSafe for WebsocketCommands
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