peermerge

Struct Peermerge

Source
pub struct Peermerge<T, U>{ /* private fields */ }
Expand description

Peermerge is the main abstraction and a store for multiple documents.

Implementations§

Source§

impl<T, U> Peermerge<T, U>
where T: RandomAccess + Debug + Send + 'static, U: FeedPersistence,

Source

pub fn peer_id(&self) -> PeerId

Get my peer id

Source

pub async fn peer_ids( &self, document_id: &DocumentId, ) -> Result<Vec<PeerId>, PeermergeError>

Get all known peer ids in a document

Source

pub fn default_peer_header(&self) -> NameDescription

Get my default peer header given to a new document

Source

pub async fn peer_header( &self, document_id: &DocumentId, peer_id: &PeerId, ) -> Result<Option<NameDescription>, PeermergeError>

Get the current peer header value in a new document

Source

pub async fn set_state_event_sender( &mut self, state_event_sender: Option<UnboundedSender<StateEvent>>, ) -> Result<(), PeermergeError>

Add or change the state event sender. The sender can already be given when peermerge is created but sometimes it’s more convinient to set it later.

Source

pub async fn transact<F, O>( &self, document_id: &DocumentId, cb: F, ) -> Result<O, PeermergeError>

Read from a document in a single transaction

Source

pub async fn transact_mut<F, O>( &mut self, document_id: &DocumentId, cb: F, change_id: Option<Vec<u8>>, ) -> Result<O, PeermergeError>
where F: FnOnce(&mut AutomergeDoc) -> Result<O, AutomergeError>,

Read and write to a document in a single transaction. change_id is an optional parameter that will be returned in the corresponding DocumentChanged StateEvent.

Source

pub async fn watch( &mut self, document_id: &DocumentId, ids: Option<Vec<ObjId>>, ) -> Result<(), PeermergeError>

Set watching to list of Automerge object ids so that DocumentChanged StateEvents are returned only from changes to those objects. None means sending events of all changes which is the default.

Source

pub async fn reserve_object<O: AsRef<ObjId>>( &mut self, document_id: &DocumentId, obj: O, ) -> Result<(), PeermergeError>

Reserve a given object for only local changes, preventing any peers from making changes to it at the same time before unreserve_object has been called. Useful especially when editing a text to avoid having to update remote changes to the field while typing. Reserve is not persisted to storage.

Source

pub async fn unreserve_object<O: AsRef<ObjId>>( &mut self, document_id: &DocumentId, obj: O, ) -> Result<(), PeermergeError>

Un-reserve a given object previously reserved with reserve_object.

Source

pub async fn sharing_info( &self, document_id: &DocumentId, ) -> Result<DocumentSharingInfo, PeermergeError>

Get sharing information about a document.

Source

pub async fn document_secret( &self, document_id: &DocumentId, ) -> Result<Option<String>, PeermergeError>

Get the document secret from a given document_id.

Source

pub async fn reattach_secret( &self, document_id: &DocumentId, ) -> Result<String, PeermergeError>

Get the reattach secret of a given document_id. Useful only for in-memory storage.

Source

pub async fn protocol_ids(&self) -> Result<Vec<Vec<u8>>, PeermergeError>

Get all connected protocol ids

Source

pub async fn disconnect_protocol( &mut self, protocol_id: &[u8], ) -> Result<bool, PeermergeError>

Disconnect protocol by id, returns if protocol with id was found

Source

pub async fn disconnect_all_protocols( &mut self, ) -> Result<usize, PeermergeError>

Disconnect all protocols, returns total number of protocols disconnected

Source§

impl Peermerge<RandomAccessMemory, FeedMemoryPersistence>

Source

pub async fn new_memory( options: PeermergeMemoryOptions, ) -> Result<Self, PeermergeError>

Create a new memory Peermerge

Source

pub async fn create_new_document_memory<F, O>( &mut self, options: CreateNewDocumentMemoryOptions, init_cb: F, change_id: Option<Vec<u8>>, ) -> Result<(DocumentInfo, O), PeermergeError>
where F: FnOnce(&mut Transaction<'_>) -> Result<O, AutomergeError>,

Create a new document in-memory

Source

pub async fn attach_document_memory( &mut self, options: AttachDocumentMemoryOptions, ) -> Result<DocumentInfo, PeermergeError>

Attach an existing document in-memory

Source

pub async fn connect_protocol_memory<T>( &mut self, protocol_id: &[u8], protocol: &mut FeedProtocol<T>, ) -> Result<(), PeermergeError>
where T: IO,

Connect peer protocol in-memory

Source§

impl Peermerge<RandomAccessDisk, FeedDiskPersistence>

Source

pub async fn new_disk( options: PeermergeDiskOptions, ) -> Result<Self, PeermergeError>

Create a new disk Peermerge

Source

pub async fn document_infos_disk( data_root_dir: &Path, ) -> Result<Option<Vec<DocumentInfo>>, PeermergeError>

Get information about possible documents stored to a given root directory

Source

pub async fn open_disk(options: OpenDiskOptions) -> Result<Self, PeermergeError>

Open peermerge stored to disk

Source

pub async fn create_new_document_disk<F, O>( &mut self, options: CreateNewDocumentDiskOptions, init_cb: F, change_id: Option<Vec<u8>>, ) -> Result<(DocumentInfo, O), PeermergeError>
where F: FnOnce(&mut Transaction<'_>) -> Result<O, AutomergeError>,

Create a new document on disk

Source

pub async fn attach_document_disk( &mut self, options: AttachDocumentDiskOptions, ) -> Result<DocumentInfo, PeermergeError>

Attach existing document to disk

Source

pub async fn connect_protocol_disk<T>( &mut self, protocol_id: &[u8], protocol: &mut FeedProtocol<T>, ) -> Result<(), PeermergeError>
where T: IO,

Connect peer protocol to disk

Trait Implementations§

Source§

impl<T, U> Clone for Peermerge<T, U>

Source§

fn clone(&self) -> Self

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<T, U> Debug for Peermerge<T, U>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, U> Freeze for Peermerge<T, U>

§

impl<T, U> !RefUnwindSafe for Peermerge<T, U>

§

impl<T, U> Send for Peermerge<T, U>

§

impl<T, U> Sync for Peermerge<T, U>

§

impl<T, U> Unpin for Peermerge<T, U>

§

impl<T, U> !UnwindSafe for Peermerge<T, U>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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