Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

A connected relay client.

Implementations§

Source§

impl Client

Source

pub async fn connect(addr: &str) -> Result<Self, SyncError>

Connect to a relay server.

Source

pub fn builder() -> ClientBuilder

Start building a client.

Source

pub fn client_id(&self) -> Option<Uuid>

Get the client’s UUID assigned by the server.

Returns None before the first successful join + recv (the server assigns the ID and sends it in the Joined event).

Source

pub async fn join( &mut self, room_id: &str, data: Option<&[u8]>, ) -> Result<(), SyncError>

Join a room. If room does not exist, returns SyncError::RoomNotFound

Source

pub async fn echo_test(&mut self, data: &[u8]) -> Result<(), SyncError>

An Echo check that can be performed at any time to verify the connection is alive and measure latency. Prefers raw bytes to avoid serialization overhead and perform after Client::join, limit at max_payload

Source

pub async fn leave(&mut self) -> Result<(), SyncError>

Leave the current room.

Source

pub async fn ping(&mut self) -> Result<(), SyncError>

Send a ping (keep-alive).

Source

pub async fn broadcast(&mut self, data: &[u8]) -> Result<(), SyncError>

Broadcast raw bytes to all peers in the current room.

Source

pub async fn recv(&mut self) -> Result<Option<ServerEvent>, SyncError>

Receive the next server event. Ping/pong keepalive is handled internally Returns Ok(None) on clean disconnect.

Auto Trait Implementations§

§

impl Freeze for Client

§

impl RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnwindSafe for Client

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, 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.