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,
impl<P> PersistentAutomerge<P>where
P: Persister + 'static,
pub const fn document(&self) -> &Automerge
pub fn document_mut(&mut self) -> &mut Automerge
pub fn transact<F, O, E>( &mut self, f: F, ) -> TransactionResult<O, (), E, P::Error>
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,
Sourcepub fn apply_changes(
&mut self,
changes: impl IntoIterator<Item = Change>,
) -> Result<(), Error<P::Error>>
pub fn apply_changes( &mut self, changes: impl IntoIterator<Item = Change>, ) -> Result<(), Error<P::Error>>
Apply changes to this document.
pub fn apply_changes_with<I: IntoIterator<Item = Change>, Obs: OpObserver>( &mut self, changes: I, op_observer: Option<&mut Obs>, ) -> Result<(), Error<P::Error>>
Sourcepub fn load(persister: P) -> Result<Self, Error<P::Error>>
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();Sourcepub fn compact(&mut self, old_peer_ids: &[&[u8]]) -> Result<(), Error<P::Error>>
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();Sourcepub fn generate_sync_message(
&mut self,
peer_id: Vec<u8>,
) -> Result<Option<Message>, Error<P::Error>>
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();Sourcepub fn receive_sync_message(
&mut self,
peer_id: Vec<u8>,
message: Message,
) -> Result<(), Error<P::Error>>
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.
Sourcepub fn receive_sync_message_with<Obs: OpObserver>(
&mut self,
peer_id: Vec<u8>,
message: Message,
op_observer: &mut Obs,
) -> Result<(), Error<P::Error>>
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.
Sourcepub fn flush(&mut self) -> Result<usize, P::Error>
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.
Sourcepub fn close(self) -> Result<P, P::Error>
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.
Sourcepub fn persister_mut(&mut self) -> &mut P
pub fn persister_mut(&mut self) -> &mut P
Obtain a mut reference to the persister.
Trait Implementations§
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> 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> 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