pub struct Session { /* private fields */ }
Expand description
A handle into the websocket session.
This type can be used to send messages into the websocket.
Implementations§
source§impl Session
impl Session
sourcepub async fn text(&mut self, msg: impl Into<ByteString>) -> Result<(), Closed>
pub async fn text(&mut self, msg: impl Into<ByteString>) -> Result<(), Closed>
Send text into the websocket
ⓘ
if session.text("Some text").await.is_err() {
// session closed
}
sourcepub async fn binary(&mut self, msg: impl Into<Bytes>) -> Result<(), Closed>
pub async fn binary(&mut self, msg: impl Into<Bytes>) -> Result<(), Closed>
Send raw bytes into the websocket
ⓘ
if session.binary(b"some bytes").await.is_err() {
// session closed
}
sourcepub async fn ping(&mut self, msg: &[u8]) -> Result<(), Closed>
pub async fn ping(&mut self, msg: &[u8]) -> Result<(), Closed>
Ping the client
For many applications, it will be important to send regular pings to keep track of if the client has disconnected
ⓘ
if session.ping(b"").await.is_err() {
// session is closed
}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Session
impl !RefUnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl !UnwindSafe for Session
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