pub struct PersistentAutoCommit<P> { /* private fields */ }Expand description
A wrapper for a persister and an automerge document.
Implementations§
source§impl<P> PersistentAutoCommit<P>where
P: Persister + 'static,
impl<P> PersistentAutoCommit<P>where P: Persister + 'static,
pub const fn document(&self) -> &AutoCommit
sourcepub fn document_mut(&mut self) -> &mut AutoCommit
pub fn document_mut(&mut self) -> &mut AutoCommit
UNSAFE: this may lead to changes not being immediately persisted
sourcepub fn transact<F: FnOnce(&mut AutoCommit) -> Result<O, E>, O, E>(
&mut self,
f: F
) -> Result<O, E>
pub fn transact<F: FnOnce(&mut AutoCommit) -> Result<O, E>, O, E>( &mut self, f: F ) -> Result<O, E>
Make changes to the document but don’t immediately persist changes.
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 = PersistentAutoCommit::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.
doc.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 = doc.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 flush(&mut self) -> Result<usize, Error<P::Error>>
pub fn flush(&mut self) -> Result<usize, Error<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_transaction(&mut self) -> Result<(), Error<P::Error>>
pub fn close_transaction(&mut self) -> Result<(), Error<P::Error>>
Close any current transaction and write out the changes to disk.