Skip to main content

Client

Struct Client 

Source
pub struct Client {
    pub id: ClientId,
    pub relation: Option<ClientRelation>,
    pub state: EditingState,
    pub metadata: ClientMetadata,
    pub ring_buffer: ClientRingBuffer,
}
Expand description

A client in a session.

All clients have EditingState for local viewport, smooth transitions, and pending keys buffer. The relation field controls input routing.

§Property Invariants

  1. relation = None implies client is independent (input → self)
  2. relation = Some(Following{target}) implies input is ignored
  3. relation = Some(Sharing{with}) implies input routes to with
  4. All clients ALWAYS have state: EditingState (non-optional)
  5. No cycles allowed: if A → B, then B cannot → A (directly or transitively)

Fields§

§id: ClientId

Unique client identifier.

§relation: Option<ClientRelation>

Relation to another client. None = independent.

§state: EditingState

Editing state (mode, cursor, windows, etc.). ALWAYS present.

§metadata: ClientMetadata

Client metadata (type, display name, join time).

§ring_buffer: ClientRingBuffer

Per-client debug ring buffer (Phase #478/#481).

Implementations§

Source§

impl Client

Source

pub fn new(id: ClientId, metadata: ClientMetadata) -> Self

Create a new independent client with default editing state.

Source

pub fn with_mode_stack( id: ClientId, metadata: ClientMetadata, mode_stack: ModeStack, ) -> Self

Create client with specific mode stack.

Source

pub fn with_mode_stack_and_window( id: ClientId, metadata: ClientMetadata, mode_stack: ModeStack, window: Window, ) -> Self

Create client with mode stack and initial window.

Source

pub const fn ring_buffer(&self) -> &ClientRingBuffer

Get the ring buffer for this client.

Source

pub const fn is_independent(&self) -> bool

Check if client is independent (no relation).

Source

pub const fn is_following(&self) -> bool

Check if client is following another.

Source

pub const fn is_sharing(&self) -> bool

Check if client is sharing with another.

Source

pub const fn target_id(&self) -> Option<ClientId>

Get the target client ID (for Following/Sharing), or None if independent.

Source

pub fn validate_relation_change( client: &Self, new_relation: Option<ClientRelation>, clients: &HashMap<ClientId, Self>, ) -> TransitionResult

Validate a relation change without applying it.

This is a static method that checks if a relation change is valid without mutating the client. Used by Session::set_client_relation().

§Validation Rules
  1. Cannot target self (returns CannotTargetSelf)
  2. Target must exist (returns TargetNotFound)
  3. Cannot create cycles (returns WouldCreateCycle)
  4. Following → Sharing with same target may require cursor sync
Source

pub fn try_set_relation( &mut self, new_relation: Option<ClientRelation>, clients: &HashMap<ClientId, Self>, ) -> TransitionResult

Attempt to change relation with validation.

Returns TransitionResult indicating success or required preconditions.

§Validation Rules
  1. Cannot target self (returns CannotTargetSelf)
  2. Target must exist (returns TargetNotFound)
  3. Cannot create cycles (returns WouldCreateCycle)
  4. Following → Sharing with same target may require cursor sync
§Examples
// Independent to Following
let result = client.try_set_relation(
    Some(ClientRelation::Following { target: other_id }),
    &clients,
);
assert!(result.is_ok());

// Back to independent
let result = client.try_set_relation(None, &clients);
assert!(result.is_ok());
Source

pub fn sync_cursor_to(&mut self, target: &Self)

Sync cursor to target client’s position.

Used for Following → Sharing transitions that require cursor alignment.

Source

pub const fn set_relation_unchecked(&mut self, relation: Option<ClientRelation>)

Force set relation without validation.

Use sparingly - prefer try_set_relation() for safety. This is useful for initialization or internal operations where validation has already been performed.

Source

pub fn effective_state<'a>( &'a self, clients: &'a HashMap<ClientId, Self>, ) -> Option<&'a EditingState>

Get the effective state for display.

  • Independent: own state
  • Following: target’s state (with depth limit)
  • Sharing: target’s state (with depth limit)

Returns None if the target/chain doesn’t exist or if there’s a cycle.

Source

pub fn effective_state_mut<'a>( &'a self, clients: &'a mut HashMap<ClientId, Self>, ) -> Option<&'a mut EditingState>

Get mutable reference to the effective state for input routing.

  • Independent: Returns None (caller should use self.state directly)
  • Following: Returns None (input is ignored)
  • Sharing: Returns target’s state (recursively)

Note: For independent clients, the caller must handle self.state specially due to Rust borrow rules (can’t borrow self and return reference to self.state).

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnsafeUnpin 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more