collab-common 0.0.7

Code shared by collab's client and server
Documentation
use cola::EncodedReplica;
use serde::{Deserialize, Serialize};

use crate::Cursor;

/// TODO: docs
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Document {
    cursors: Vec<Cursor>,

    /// TODO: docs
    replica: cola::EncodedReplica,

    /// The text of the document.
    text: String,
}

impl Document {
    /// TODO: docs
    #[inline(always)]
    pub fn cursors(&self) -> impl ExactSizeIterator<Item = Cursor> + '_ {
        self.cursors.iter().copied()
    }

    /// TODO: docs
    #[inline(always)]
    pub(crate) fn new<S>(
        cursors: Vec<Cursor>,
        replica: EncodedReplica,
        text: S,
    ) -> Self
    where
        S: Into<String>,
    {
        Self { cursors, replica, text: text.into() }
    }

    /// TODO: docs
    #[inline(always)]
    pub fn replica(&self) -> &EncodedReplica {
        &self.replica
    }

    /// TODO: docs
    #[inline(always)]
    pub fn text(&self) -> &str {
        &self.text
    }
}