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 with an in-memory transport (for testing).

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.

Source

pub fn peer_id(&self) -> &PeerId

Get the local peer ID.

Source

pub fn user_name(&self) -> &str

Get the user name.

Source

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

Get the transport.

Source

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

Create a new collaborative session.

Source

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

Get an existing session.

Source

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

Close a session.

Source

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

List all active session IDs.

Source

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

Connect to a peer.

Source

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

Disconnect from a peer.

Source

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

Get list of connected peers.

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> !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