Skip to main content

Client

Struct Client 

Source
pub struct Client<T: NetworkTransport> { /* private fields */ }
Expand description

The main MDCS client for collaborative editing.

The client manages sessions, documents, and network connections.

§Example

use mdcs_sdk::{Client, ClientConfig};

// Create a client
let config = ClientConfig {
    user_name: "Alice".to_string(),
    ..Default::default()
};
let client = Client::new_with_memory_transport(config);

// Create a session
let session = client.create_session("my-session");

// Open a document
let doc = session.open_text_doc("shared-doc");
doc.write().insert(0, "Hello, world!");

Implementations§

Source§

impl Client<MemoryTransport>

Source

pub fn new_with_memory_transport(config: ClientConfig) -> Self

Create a new client backed by MemoryTransport.

This constructor is ideal for tests, local demos, and examples where all peers run in the same process.

Source§

impl<T: NetworkTransport> Client<T>

Source

pub fn new(peer_id: PeerId, transport: Arc<T>, config: ClientConfig) -> Self

Create a new client with a custom transport implementation.

Use this constructor when integrating with a real networking backend (WebSocket, QUIC, custom RPC, etc.).

Source

pub fn peer_id(&self) -> &PeerId

Return the unique identifier of this local peer.

Source

pub fn user_name(&self) -> &str

Return the configured local user name.

Source

pub fn transport(&self) -> &Arc<T>

Return the transport used by this client.

Source

pub fn create_session(&self, session_id: impl Into<String>) -> Arc<Session<T>>

Create or fetch a collaborative session by ID.

If the session already exists, this returns the same shared instance.

Source

pub fn get_session(&self, session_id: &str) -> Option<Arc<Session<T>>>

Get an existing session if it has already been created on this client.

Source

pub fn close_session(&self, session_id: &str)

Close a local session handle and remove it from the client cache.

This does not notify remote peers directly; use higher-level app signaling if your protocol requires explicit leave semantics.

Source

pub fn session_ids(&self) -> Vec<String>

List all currently active local session IDs.

Source

pub async fn connect_peer(&self, peer_id: &PeerId) -> Result<(), SdkError>

Establish a transport-level connection to a peer.

§Errors

Returns SdkError::ConnectionFailed if the underlying transport cannot connect to the target peer.

Source

pub async fn disconnect_peer(&self, peer_id: &PeerId) -> Result<(), SdkError>

Disconnect from a peer.

§Errors

Returns SdkError::NetworkError if the transport reports a failure while disconnecting.

Source

pub async fn connected_peers(&self) -> Vec<Peer>

Return the current list of connected peers reported by the transport.

Auto Trait Implementations§

§

impl<T> Freeze for Client<T>

§

impl<T> !RefUnwindSafe for Client<T>

§

impl<T> Send for Client<T>

§

impl<T> Sync for Client<T>

§

impl<T> Unpin for Client<T>

§

impl<T> UnsafeUnpin for Client<T>

§

impl<T> !UnwindSafe for Client<T>

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.
Source§

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

Source§

fn vzip(self) -> V