[−][src]Struct yarws::Socket
Represent a WebSocket connection. Used for sending and receiving messages.
Fields
no: usize
Methods
impl Socket
[src]
pub async fn recv<'_>(&'_ mut self) -> Option<Msg>
[src]
Receives Msg from the other side of the Socket connection. None is returned if the socket is closed.
Examples
Usually used in while loop:
while let Some(msg) = socket.recv().await { // process msg }
pub async fn send<'_>(&'_ mut self, msg: Msg) -> Result<(), Error>
[src]
Sends Msg to the other side of the Socket connection. Errors if the socket is already closed.
Examples
Echo example. Receive Msgs and replay with the same Msg.
async fn echo(mut socket: Socket) -> Result<(), Error> { while let Some(msg) = socket.recv().await { socket.send(msg).await?; } Ok(()) }
pub async fn into_channel(self) -> (Sender<Msg>, Receiver<Msg>)
[src]
Transforms Socket into pair of mpsc channels for sending/receiving Msgs.
In some cases it is more convenient to have channels instead of calling methods. Ownership of each side of the channel can be moved to the different function.
pub fn into_text(self) -> TextSocket
[src]
Transforms Socket into TextSocket which is more convenient for handling text only messages.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Socket
impl Send for Socket
impl Sync for Socket
impl Unpin for Socket
impl !UnwindSafe for Socket
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,