Struct automerge::patches::PatchLog

source ·
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}, patches::TextRepresentation};
let doc = AutoCommit::new();
let sync_message: Message = unimplemented!();
let mut sync_state = SyncState::new();
let mut patch_log = PatchLog::active(TextRepresentation::String);
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

source

pub fn new(active: bool, text_rep: TextRepresentation) -> Self

Create a new PatchLog

§Arguments
  • active - If true the log will record all changes made to the document. If false then no changes will be recorded.
  • text_rep - How text will be represented in the generated patches

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.

source

pub fn inactive(text_rep: TextRepresentation) -> Self

Create a new PatchLog which doesn’t record any changes.

See also: PatchLog::new() for a more detailed explanation.

source

pub fn null() -> Self

source

pub fn active(text_rep: TextRepresentation) -> Self

Create a new PatchLog which does record changes.

See also: PatchLog::new() for a more detailed explanation.

Trait Implementations§

source§

impl Clone for PatchLog

source§

fn clone(&self) -> PatchLog

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for PatchLog

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more