Skip to main content

oxigdal_sync/ot/
mod.rs

1//! Operational Transformation (OT)
2//!
3//! This module provides operational transformation for concurrent text editing.
4//! OT allows multiple users to edit the same document concurrently while
5//! maintaining consistency.
6
7pub mod composer;
8pub mod text_operation;
9
10pub use composer::OperationComposer;
11pub use text_operation::{Operation, TextOperation};
12
13use crate::SyncResult;
14use serde::{Deserialize, Serialize};
15
16/// Trait for transformable operations
17pub trait Transform: Clone + Serialize + for<'de> Deserialize<'de> {
18    /// Transforms this operation against another concurrent operation
19    ///
20    /// Returns the transformed version of this operation that can be
21    /// applied after the other operation.
22    ///
23    /// # Arguments
24    ///
25    /// * `other` - The concurrent operation to transform against
26    ///
27    /// # Returns
28    ///
29    /// The transformed operation
30    fn transform(&self, other: &Self) -> SyncResult<Self>;
31
32    /// Composes this operation with another sequential operation
33    ///
34    /// Returns a single operation that has the same effect as applying
35    /// this operation followed by the other operation.
36    ///
37    /// # Arguments
38    ///
39    /// * `other` - The operation to compose with
40    ///
41    /// # Returns
42    ///
43    /// The composed operation
44    fn compose(&self, other: &Self) -> SyncResult<Self>;
45
46    /// Inverts this operation
47    ///
48    /// Returns an operation that undoes the effect of this operation.
49    ///
50    /// # Returns
51    ///
52    /// The inverted operation
53    fn invert(&self) -> SyncResult<Self>;
54}