PersistentAutomerge

Struct PersistentAutomerge 

Source
pub struct PersistentAutomerge<P> { /* private fields */ }
Expand description

A wrapper for a persister and an automerge document.

Implementations§

Source§

impl<P> PersistentAutomerge<P>
where P: Persister + 'static,

Source

pub const fn document(&self) -> &Automerge

Source

pub fn document_mut(&mut self) -> &mut Automerge

Source

pub fn transact<F, O, E>( &mut self, f: F, ) -> TransactionResult<O, (), E, P::Error>
where F: FnOnce(&mut Transaction<'_, UnObserved>) -> Result<O, E>,

Source

pub fn transact_with<F, O, E, C, Obs>( &mut self, c: C, f: F, ) -> TransactionResult<O, Obs, E, P::Error>
where F: FnOnce(&mut Transaction<'_, Observed<Obs>>) -> Result<O, E>, C: FnOnce(&O) -> CommitOptions, Obs: OpObserver + BranchableObserver + Default,

Source

pub fn apply_changes( &mut self, changes: impl IntoIterator<Item = Change>, ) -> Result<(), Error<P::Error>>

Apply changes to this document.

Source

pub fn apply_changes_with<I: IntoIterator<Item = Change>, Obs: OpObserver>( &mut self, changes: I, op_observer: Option<&mut Obs>, ) -> Result<(), Error<P::Error>>

Source

pub fn load(persister: P) -> Result<Self, Error<P::Error>>

Load the persisted changes (both individual changes and a document) from storage and rebuild the Document.

let persister = MemoryPersister::default();
let doc = PersistentAutomerge::load(persister).unwrap();
Source

pub fn compact(&mut self, old_peer_ids: &[&[u8]]) -> Result<(), Error<P::Error>>

Compact the storage.

This first obtains the changes currently in the document, saves the document and persists the saved document. We then can remove the previously obtained changes one by one.

It also clears out the storage used up by old sync states for peers by removing those given in old_peers.

document.compact(&[]).unwrap();
Source

pub fn generate_sync_message( &mut self, peer_id: Vec<u8>, ) -> Result<Option<Message>, Error<P::Error>>

Generate a sync message to be sent to a peer document.

Peer id is intentionally low level and up to the user as it can be a DNS name, IP address or something else.

This internally retrieves the previous sync state from storage and saves the new one afterwards.

let message = document.generate_sync_message(vec![]).unwrap();
Source

pub fn receive_sync_message( &mut self, peer_id: Vec<u8>, message: Message, ) -> Result<(), Error<P::Error>>

Receive a sync message from a peer document.

Peer id is intentionally low level and up to the user as it can be a DNS name, IP address or something else.

This internally retrieves the previous sync state from storage and saves the new one afterwards.

Source

pub fn receive_sync_message_with<Obs: OpObserver>( &mut self, peer_id: Vec<u8>, message: Message, op_observer: &mut Obs, ) -> Result<(), Error<P::Error>>

Receive a sync message from a peer document.

Peer id is intentionally low level and up to the user as it can be a DNS name, IP address or something else.

This internally retrieves the previous sync state from storage and saves the new one afterwards.

Source

pub fn flush(&mut self) -> Result<usize, P::Error>

Flush any data out to storage returning the number of bytes flushed.

§Errors

Returns the error returned by the persister during flushing.

Source

pub fn close(self) -> Result<P, P::Error>

Close the document.

This calls flush on the persister and returns it for potential use in other documents.

§Errors

Returns the error from flushing.

Source

pub const fn persister(&self) -> &P

Obtain a reference to the persister.

Source

pub fn persister_mut(&mut self) -> &mut P

Obtain a mut reference to the persister.

Source

pub fn reset_sync_state(&mut self, peer_id: &[u8]) -> Result<(), P::Error>

Reset the sync state for a peer.

This is typically used when a peer disconnects, we need to reset the sync state for them as they may come back up with different state.

Trait Implementations§

Source§

impl<P: Debug> Debug for PersistentAutomerge<P>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<P> Freeze for PersistentAutomerge<P>
where P: Freeze,

§

impl<P> RefUnwindSafe for PersistentAutomerge<P>
where P: RefUnwindSafe,

§

impl<P> Send for PersistentAutomerge<P>
where P: Send,

§

impl<P> Sync for PersistentAutomerge<P>
where P: Sync,

§

impl<P> Unpin for PersistentAutomerge<P>
where P: Unpin,

§

impl<P> UnwindSafe for PersistentAutomerge<P>
where P: UnwindSafe,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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