operational-transform
A library for Operational Transformation
Operational transformation (OT) is a technology for supporting a range of collaboration functionalities in advanced collaborative software systems. [1]
When working on the same document over the internet concurrent operations from multiple users might be in conflict. Operational Transform can help to resolve conflicts in such a way that docuemnts stay in sync.
The basic operations that are supported are:
- Retain(n): Move the cursor
n
positions forward - Delete(n): Delete
n
characters at the current position - Insert(s): Insert the string
s
at the current position
This library can be used to...
... compose sequences of operations:
use OperationSeq;
let mut a = default;
a.insert;
let mut b = default;
b.retain;
b.insert;
let after_a = a.apply.unwrap;
let after_b = b.apply.unwrap;
let c = a.compose.unwrap;
let after_ab = a.compose.unwrap.apply.unwrap;
assert_eq!;
... transform sequences of operations
use OperationSeq;
let s = "abc";
let mut a = default;
a.retain;
a.insert;
let mut b = default;
b.retain;
b.insert;
let = a.transform.unwrap;
let ab_prime = a.compose.unwrap;
let ba_prime = b.compose.unwrap;
let after_ab_prime = ab_prime.apply.unwrap;
let after_ba_prime = ba_prime.apply.unwrap;
assert_eq!;
assert_eq!;
... invert sequences of operations
use OperationSeq;
let s = "abc";
let mut o = default;
o.retain;
o.insert;
let p = o.invert;
assert_eq!;
Features
Serialisation is supporeted by using the serde
feature.
- Delete(n) will be serialized to -n
- Insert(s) will be serialized to "{s}"
- Retain(n) will be serailized to n
use OperationSeq;
use serde_json;
let o: OperationSeq = from_str.unwrap;
let mut o_exp = default;
o_exp.retain;
o_exp.delete;
o_exp.insert;
assert_eq!;
Acknowledgement
In the current state the code is ported from here. It might change in the future as there is much room for optimisation and also usability.