Struct PatchLog
pub struct PatchLog { /* private fields */ }Expand description
A record of changes made to a document
It is often necessary to maintain a materialized view of the current state of a document. E.g.
in a text editor you may be rendering the current state a text field in the UI. In order to
efficiently update the state of the materialized view any method which adds operations to the
document has a variant which takes a PatchLog as an argument. This allows the caller to
record the changes made and then use either crate::Automerge::make_patches() or
crate::AutoCommit::make_patches() to generate a Vec<Patch> which can be used to update the
materialized view.
A PatchLog is a set of relative changes. It represents the changes required to go from the
state at one point in history to another. What those two points are depends on how you use the
log. A typical reason to create a PatchLog is to record the changes made by remote peers.
Consider this example:
SyncState, SyncDoc}, TextEncoding};
let doc = AutoCommit::new();
let sync_message: Message = unimplemented!();
let mut sync_state = SyncState::new();
let mut patch_log = PatchLog::active();
doc.sync().receive_sync_message_log_patches(&mut sync_state, sync_message, &mut patch_log);
// These patches represent the changes needed to go from the state of the document before the
// sync message was received, to the state after.
let patches = doc.make_patches(&mut patch_log);Implementations§
§impl PatchLog
impl PatchLog
pub fn new(active: bool) -> PatchLog
pub fn new(active: bool) -> PatchLog
Create a new PatchLog
§Arguments
active- Iftruethe log will record all changes made to the document. Iffalsethen no changes will be recorded.
Why, you ask, would you create a PatchLog which doesn’t record any changes? Operations
which record patches are more expensive, so sometimes you may wish to turn off patch
logging for parts of the application, but not others; but you don’t want to complicate your
code with an Option<PatchLog>. In that case you can use an inactive PatchLog.
pub fn inactive() -> PatchLog
pub fn inactive() -> PatchLog
Create a new PatchLog which doesn’t record any changes.
See also: PatchLog::new() for a more detailed explanation.
pub fn null() -> PatchLog
pub fn active() -> PatchLog
pub fn active() -> PatchLog
Create a new PatchLog which does record changes.
See also: PatchLog::new() for a more detailed explanation.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PatchLog
impl RefUnwindSafe for PatchLog
impl Send for PatchLog
impl Sync for PatchLog
impl Unpin for PatchLog
impl UnsafeUnpin for PatchLog
impl UnwindSafe for PatchLog
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more