pub struct Doc { /* private fields */ }Expand description
Document handle
Implementations§
Source§impl Doc
impl Doc
Sourcepub fn id(&self) -> NamespaceId
pub fn id(&self) -> NamespaceId
Returns the document id of this doc.
Sourcepub async fn set_bytes(
&self,
author_id: AuthorId,
key: impl Into<Bytes>,
value: impl Into<Bytes>,
) -> Result<Hash>
pub async fn set_bytes( &self, author_id: AuthorId, key: impl Into<Bytes>, value: impl Into<Bytes>, ) -> Result<Hash>
Sets the content of a key to a byte array.
Sourcepub async fn set_hash(
&self,
author_id: AuthorId,
key: impl Into<Bytes>,
hash: Hash,
size: u64,
) -> Result<()>
pub async fn set_hash( &self, author_id: AuthorId, key: impl Into<Bytes>, hash: Hash, size: u64, ) -> Result<()>
Sets an entry on the doc via its key, hash, and size.
Sourcepub async fn del(
&self,
author_id: AuthorId,
prefix: impl Into<Bytes>,
) -> Result<usize>
pub async fn del( &self, author_id: AuthorId, prefix: impl Into<Bytes>, ) -> Result<usize>
Deletes entries that match the given author and key prefix.
This inserts an empty entry with the key set to prefix, effectively clearing all other
entries whose key starts with or is equal to the given prefix.
Returns the number of entries deleted.
Sourcepub async fn get_exact(
&self,
author: AuthorId,
key: impl AsRef<[u8]>,
include_empty: bool,
) -> Result<Option<Entry>>
pub async fn get_exact( &self, author: AuthorId, key: impl AsRef<[u8]>, include_empty: bool, ) -> Result<Option<Entry>>
Returns an entry for a key and author.
Optionally also returns the entry unless it is empty (i.e. a deletion marker).
Sourcepub async fn get_many(
&self,
query: impl Into<Query>,
) -> Result<impl Stream<Item = Result<Entry>>>
pub async fn get_many( &self, query: impl Into<Query>, ) -> Result<impl Stream<Item = Result<Entry>>>
Returns all entries matching the query.
Sourcepub async fn get_one(&self, query: impl Into<Query>) -> Result<Option<Entry>>
pub async fn get_one(&self, query: impl Into<Query>) -> Result<Option<Entry>>
Returns a single entry.
Shares this document with peers over a ticket.
Sourcepub async fn start_sync(&self, peers: Vec<NodeAddr>) -> Result<()>
pub async fn start_sync(&self, peers: Vec<NodeAddr>) -> Result<()>
Starts to sync this document with a list of peers.
Sourcepub async fn subscribe(
&self,
) -> Result<impl Stream<Item = Result<LiveEvent>> + Send + Unpin + 'static>
pub async fn subscribe( &self, ) -> Result<impl Stream<Item = Result<LiveEvent>> + Send + Unpin + 'static>
Subscribes to events for this document.
Sourcepub async fn set_download_policy(&self, policy: DownloadPolicy) -> Result<()>
pub async fn set_download_policy(&self, policy: DownloadPolicy) -> Result<()>
Sets the download policy for this document
Sourcepub async fn get_download_policy(&self) -> Result<DownloadPolicy>
pub async fn get_download_policy(&self) -> Result<DownloadPolicy>
Returns the download policy for this document
Sourcepub async fn get_sync_peers(&self) -> Result<Option<Vec<PeerIdBytes>>>
pub async fn get_sync_peers(&self) -> Result<Option<Vec<PeerIdBytes>>>
Returns sync peers for this document
Sourcepub async fn import_file(
&self,
blobs: &Store,
author: AuthorId,
key: Bytes,
path: impl AsRef<Path>,
import_mode: ImportMode,
) -> Result<ImportFileProgress>
pub async fn import_file( &self, blobs: &Store, author: AuthorId, key: Bytes, path: impl AsRef<Path>, import_mode: ImportMode, ) -> Result<ImportFileProgress>
Adds an entry from an absolute file path