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>
impl<S: SyncState> NomadClient<S>
Sourcepub async fn connect(
config: ClientConfig,
initial_state: S,
) -> Result<(Self, StateReceiver<S>), ClientError>
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.
Sourcepub async fn client_state(&self) -> ClientState
pub async fn client_state(&self) -> ClientState
Get the current client state.
Sourcepub async fn local_state(&self) -> S
pub async fn local_state(&self) -> S
Get a copy of the current local state.
Sourcepub async fn update_state(&self, new_state: S) -> Result<(), ClientError>
pub async fn update_state(&self, new_state: S) -> Result<(), ClientError>
Update the local state.
This queues the state for synchronization with the server.
Sourcepub fn state_sender(&self) -> StateSender<S>
pub fn state_sender(&self) -> StateSender<S>
Get a sender handle for state updates.
This can be cloned and used from multiple tasks.
Sourcepub async fn is_connected(&self) -> bool
pub async fn is_connected(&self) -> bool
Check if the client is connected.
Sourcepub async fn disconnect(self) -> Result<(), ClientError>
pub async fn disconnect(self) -> Result<(), ClientError>
Gracefully disconnect from the server.
Sourcepub fn server_addr(&self) -> SocketAddr
pub fn server_addr(&self) -> SocketAddr
Get the server address.
Trait Implementations§
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> 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