Awareness

Struct Awareness 

Source
pub struct Awareness {
    local_user_id: String,
    local_user_name: String,
    local_color: String,
    tracker: Arc<RwLock<PresenceTracker>>,
    event_tx: Sender<AwarenessEvent>,
}
Expand description

Awareness manager for a document or session.

Fields§

§local_user_id: String§local_user_name: String§local_color: String§tracker: Arc<RwLock<PresenceTracker>>§event_tx: Sender<AwarenessEvent>

Implementations§

Source§

impl Awareness

Source

pub fn new( local_user_id: impl Into<String>, local_user_name: impl Into<String>, ) -> Self

Create a new awareness manager for a local user.

The local user is initialized with a default color and an online presence record in the underlying tracker.

Source

pub fn local_user_id(&self) -> &str

Return the local user identifier.

Source

pub fn local_user_name(&self) -> &str

Return the local user display name.

Source

pub fn set_cursor(&self, document_id: &str, position: usize)

Set the local user’s cursor position for a document.

Emits AwarenessEvent::CursorMoved.

Source

pub fn set_selection(&self, document_id: &str, start: usize, end: usize)

Set the local user’s selection range for a document.

Emits AwarenessEvent::CursorMoved.

Source

pub fn set_status(&self, status: UserStatus)

Update the local user’s presence status.

Source

pub fn get_users(&self) -> Vec<UserPresenceInfo>

Return a snapshot of all known users and cursor states.

Source

pub fn get_cursors(&self, document_id: &str) -> Vec<CursorInfo>

Return cursor information for users active in a specific document.

Source

pub fn get_local_color(&self) -> &str

Return the local user’s assigned color string.

Source

pub fn subscribe(&self) -> Receiver<AwarenessEvent>

Subscribe to awareness updates.

This uses a broadcast channel; late subscribers receive only future events.

Source

pub fn cleanup_stale(&self)

Remove stale user entries that have not been active recently.

Auto Trait Implementations§

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

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

§

fn vzip(self) -> V