diff --git a/src/api/factory.rs b/src/api/factory.rs index 6fec49e..693c179 100644 --- a/src/api/factory.rs +++ b/src/api/factory.rs @@ -2,7 +2,7 @@ //! //! a helper trait that any string container can implement, which generates opseqs //! -//! an OperationFactory trait implementation is provided for String, but plugin developers +//! an OperationFactory trait implementation is provided for `String` and `Arc`, but plugin developers //! should implement their own operation factory interfacing directly with the editor //! buffer when possible. @@ -93,16 +93,6 @@ pub fn op_effective_range(op: &OperationSeq) -> Range { /// assert_eq!(factory, "from scratch"); /// # Ok::<(), codemp::ot::OTError>(()) /// ``` -/// -/// use [OperationFactory::canc] to remove characters at index, but backwards -/// -/// ```rust -/// # use codemp::api::OperationFactory; -/// # let mut factory = String::from("from scratch"); -/// factory = factory.canc(12, 8).apply(&factory)?; -/// assert_eq!(factory, "from"); -/// # Ok::<(), codemp::ot::OTError>(()) -/// ``` pub trait OperationFactory { /// the current content of the buffer fn content(&self) -> String; @@ -160,16 +150,6 @@ pub trait OperationFactory { out.retain(len - (pos+count)); out } - - /// delete n characters backwards at given position - fn canc(&self, pos: u64, count: u64) -> OperationSeq { - let mut out = OperationSeq::default(); - let len = self.content().len() as u64; - out.retain(pos - count); - out.delete(count); - out.retain(len - pos); - out - } } impl OperationFactory for String { @@ -177,3 +157,9 @@ impl OperationFactory for String { self.clone() } } + +impl OperationFactory for std::sync::Arc { + fn content(&self) -> String { + self.to_string() + } +} diff --git a/src/instance.rs b/src/instance.rs index 3582b22..d89bc5e 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -166,7 +166,7 @@ pub mod sync { } /// return a reference to contained tokio runtime, to spawn tasks on - pub fn rt(&self) -> &Handle { &self.runtime.handle() } + pub fn rt(&self) -> &Handle { self.runtime.handle() } /// connect and store a client session, threadsafe and sync version of [crate::client::Client::new] pub fn connect(&self, addr: &str) -> Result<(), Error> {