Socketeer

Struct Socketeer 

Source
pub struct Socketeer<RxMessage, TxMessage, const CHANNEL_SIZE: usize = 4> { /* private fields */ }
Expand description

A WebSocket client that manages the connection to a WebSocket server. The client can send and receive messages, and will transparently handle protocol messages.

§Type Parameters

  • RxMessage: The type of message that the client will receive from the server.
  • TxMessage: The type of message that the client will send to the server.
  • CHANNEL_SIZE: The size of the internal channels used to communicate between the task managing the WebSocket connection and the client.

Implementations§

Source§

impl<RxMessage: for<'a> Deserialize<'a> + Debug, TxMessage: Serialize + Debug, const CHANNEL_SIZE: usize> Socketeer<RxMessage, TxMessage, CHANNEL_SIZE>

Source

pub async fn connect( url: &str, ) -> Result<Socketeer<RxMessage, TxMessage, CHANNEL_SIZE>, Error>

Create a Socketeer connected to the provided URL. Once connected, Socketeer manages the underlying WebSocket connection, transparently handling protocol messages.

§Errors
  • If the URL cannot be parsed
  • If the WebSocket connection to the requested URL fails
Source

pub async fn next_message(&mut self) -> Result<RxMessage, Error>

Wait for the next parsed message from the WebSocket connection.

§Errors
  • If the WebSocket connection is closed or otherwise errored
  • If the message cannot be deserialized
Source

pub async fn send(&self, message: TxMessage) -> Result<(), Error>

Send a message to the WebSocket connection. This function will wait for the message to be sent before returning.

§Errors
  • If the message cannot be serialized
  • If the WebSocket connection is closed, or otherwise errored
Source

pub async fn reconnect(self) -> Result<Self, Error>

Consume self, closing down any remaining send/recieve, and return a new Socketeer instance if successful This function attempts to close the connection gracefully before returning, but will not return an error if the connection is already closed, as its intended use is to re-establish a failed connection.

§Errors
  • If a new connection cannot be established
Source

pub async fn close_connection(self) -> Result<(), Error>

Close the WebSocket connection gracefully. This function will wait for the connection to close before returning.

§Errors
  • If the WebSocket connection is already closed
  • If the WebSocket connection cannot be closed

Trait Implementations§

Source§

impl<RxMessage: Debug, TxMessage: Debug, const CHANNEL_SIZE: usize> Debug for Socketeer<RxMessage, TxMessage, CHANNEL_SIZE>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<RxMessage, TxMessage, const CHANNEL_SIZE: usize> Freeze for Socketeer<RxMessage, TxMessage, CHANNEL_SIZE>

§

impl<RxMessage, TxMessage, const CHANNEL_SIZE: usize> RefUnwindSafe for Socketeer<RxMessage, TxMessage, CHANNEL_SIZE>
where RxMessage: RefUnwindSafe, TxMessage: RefUnwindSafe,

§

impl<RxMessage, TxMessage, const CHANNEL_SIZE: usize> Send for Socketeer<RxMessage, TxMessage, CHANNEL_SIZE>
where RxMessage: Send, TxMessage: Send,

§

impl<RxMessage, TxMessage, const CHANNEL_SIZE: usize> Sync for Socketeer<RxMessage, TxMessage, CHANNEL_SIZE>
where RxMessage: Sync, TxMessage: Sync,

§

impl<RxMessage, TxMessage, const CHANNEL_SIZE: usize> Unpin for Socketeer<RxMessage, TxMessage, CHANNEL_SIZE>
where RxMessage: Unpin, TxMessage: Unpin,

§

impl<RxMessage, TxMessage, const CHANNEL_SIZE: usize> UnwindSafe for Socketeer<RxMessage, TxMessage, CHANNEL_SIZE>
where RxMessage: UnwindSafe, TxMessage: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,