NomadClient

Struct NomadClient 

Source
pub struct NomadClient<S: SyncState> { /* private fields */ }
Available on crate feature client only.
Expand description

A NOMAD protocol client.

Generic over state type S which must implement SyncState.

§Example

use nomad_protocol::client::{NomadClient, NomadClientBuilder};

let config = NomadClientBuilder::new()
    .server_addr("127.0.0.1:19999".parse()?)
    .server_public_key(server_pubkey)
    .build();

let (client, state_rx) = NomadClient::<MyState>::connect(config, initial_state).await?;

// Send state updates
client.update_state(new_state).await?;

// Receive server state updates
while let Some(server_state) = state_rx.recv().await {
    // Handle server state
}

Implementations§

Source§

impl<S: SyncState> NomadClient<S>

Source

pub async fn connect( config: ClientConfig, initial_state: S, ) -> Result<(Self, StateReceiver<S>), ClientError>

Connect to a NOMAD server.

Returns the client handle and a receiver for server state updates.

Source

pub async fn client_state(&self) -> ClientState

Get the current client state.

Source

pub async fn local_state(&self) -> S

Get a copy of the current local state.

Source

pub async fn update_state(&self, new_state: S) -> Result<(), ClientError>

Update the local state.

This queues the state for synchronization with the server.

Source

pub fn state_sender(&self) -> StateSender<S>

Get a sender handle for state updates.

This can be cloned and used from multiple tasks.

Source

pub async fn is_connected(&self) -> bool

Check if the client is connected.

Source

pub async fn disconnect(self) -> Result<(), ClientError>

Gracefully disconnect from the server.

Source

pub fn server_addr(&self) -> SocketAddr

Get the server address.

Trait Implementations§

Source§

impl<S: SyncState> Drop for NomadClient<S>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<S> Freeze for NomadClient<S>

§

impl<S> !RefUnwindSafe for NomadClient<S>

§

impl<S> Send for NomadClient<S>

§

impl<S> Sync for NomadClient<S>

§

impl<S> Unpin for NomadClient<S>

§

impl<S> !UnwindSafe for NomadClient<S>

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