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§
Source§impl PatchLog
impl PatchLog
Sourcepub fn new(active: bool) -> Self
pub fn new(active: bool) -> Self
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.
Sourcepub fn inactive() -> Self
pub fn inactive() -> Self
Create a new PatchLog which doesn’t record any changes.
See also: PatchLog::new() for a more detailed explanation.
pub fn null() -> Self
Sourcepub fn active() -> Self
pub fn active() -> Self
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 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,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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