pub struct Store { /* private fields */ }
Expand description
Manages the replicas and authors for an instance.
Implementations§
source§impl Store
impl Store
sourcepub fn persistent(path: impl AsRef<Path>) -> Result<Self>
pub fn persistent(path: impl AsRef<Path>) -> Result<Self>
Create or open a store from a path
to a database file.
The file will be created if it does not exist, otherwise it will be opened.
sourcepub fn flush(&mut self) -> Result<()>
pub fn flush(&mut self) -> Result<()>
Flush the current transaction, if any.
This is the cheapest way to ensure that the data is persisted.
sourcepub fn snapshot(&mut self) -> Result<&ReadOnlyTables>
pub fn snapshot(&mut self) -> Result<&ReadOnlyTables>
Get a read-only snapshot of the database.
This has the side effect of committing any open write transaction, so it can be used as a way to ensure that the data is persisted.
sourcepub fn snapshot_owned(&mut self) -> Result<ReadOnlyTables>
pub fn snapshot_owned(&mut self) -> Result<ReadOnlyTables>
Get an owned read-only snapshot of the database.
This will open a new read transaction. The read transaction won’t be reused for other reads.
This has the side effect of committing any open write transaction, so it can be used as a way to ensure that the data is persisted.
source§impl Store
impl Store
sourcepub fn new_replica(&mut self, namespace: NamespaceSecret) -> Result<Replica<'_>>
pub fn new_replica(&mut self, namespace: NamespaceSecret) -> Result<Replica<'_>>
Create a new replica for namespace
and persist in this store.
Create a new author key and persist it in the store.
sourcepub fn has_news_for_us(
&mut self,
namespace: NamespaceId,
heads: &AuthorHeads
) -> Result<Option<NonZeroU64>>
pub fn has_news_for_us( &mut self, namespace: NamespaceId, heads: &AuthorHeads ) -> Result<Option<NonZeroU64>>
Check if a AuthorHeads
contains entry timestamps that we do not have locally.
Returns the number of authors that the other peer has updates for.
sourcepub fn open_replica(
&mut self,
namespace_id: &NamespaceId
) -> Result<Replica<'_>, OpenError>
pub fn open_replica( &mut self, namespace_id: &NamespaceId ) -> Result<Replica<'_>, OpenError>
Open a replica from this store.
This just calls load_replica_info and then creates a new replica with the info.
sourcepub fn load_replica_info(
&mut self,
namespace_id: &NamespaceId
) -> Result<ReplicaInfo, OpenError>
pub fn load_replica_info( &mut self, namespace_id: &NamespaceId ) -> Result<ReplicaInfo, OpenError>
Load the replica info from the store.
sourcepub fn close_replica(&mut self, id: NamespaceId)
pub fn close_replica(&mut self, id: NamespaceId)
Close a replica.
sourcepub fn list_namespaces(
&mut self
) -> Result<impl Iterator<Item = Result<(NamespaceId, CapabilityKind)>>>
pub fn list_namespaces( &mut self ) -> Result<impl Iterator<Item = Result<(NamespaceId, CapabilityKind)>>>
List all replica namespaces in this store.
Get an author key from the store.
Import an author key pair.
Delete an author.
List all author keys in this store.
sourcepub fn import_namespace(
&mut self,
capability: Capability
) -> Result<ImportNamespaceOutcome>
pub fn import_namespace( &mut self, capability: Capability ) -> Result<ImportNamespaceOutcome>
Import a new replica namespace.
sourcepub fn remove_replica(&mut self, namespace: &NamespaceId) -> Result<()>
pub fn remove_replica(&mut self, namespace: &NamespaceId) -> Result<()>
Remove a replica.
Completely removes a replica and deletes both the namespace private key and all document entries.
Note that a replica has to be closed before it can be removed. The store has to enforce that a replica cannot be removed while it is still open.
sourcepub fn get_many(
&mut self,
namespace: NamespaceId,
query: impl Into<Query>
) -> Result<QueryIterator>
pub fn get_many( &mut self, namespace: NamespaceId, query: impl Into<Query> ) -> Result<QueryIterator>
Get an iterator over entries of a replica.
sourcepub fn get_exact(
&mut self,
namespace: NamespaceId,
author: AuthorId,
key: impl AsRef<[u8]>,
include_empty: bool
) -> Result<Option<SignedEntry>>
pub fn get_exact( &mut self, namespace: NamespaceId, author: AuthorId, key: impl AsRef<[u8]>, include_empty: bool ) -> Result<Option<SignedEntry>>
Get an entry by key and author.
sourcepub fn content_hashes(&mut self) -> Result<ContentHashesIterator>
pub fn content_hashes(&mut self) -> Result<ContentHashesIterator>
Get all content hashes of all replicas in the store.
Get the latest entry for each author in a namespace.
sourcepub fn register_useful_peer(
&mut self,
namespace: NamespaceId,
peer: PeerIdBytes
) -> Result<()>
pub fn register_useful_peer( &mut self, namespace: NamespaceId, peer: PeerIdBytes ) -> Result<()>
Register a peer that has been useful to sync a document.
sourcepub fn get_sync_peers(
&mut self,
namespace: &NamespaceId
) -> Result<Option<IntoIter<PeerIdBytes>>>
pub fn get_sync_peers( &mut self, namespace: &NamespaceId ) -> Result<Option<IntoIter<PeerIdBytes>>>
Get the peers that have been useful for a document.
sourcepub fn set_download_policy(
&mut self,
namespace: &NamespaceId,
policy: DownloadPolicy
) -> Result<()>
pub fn set_download_policy( &mut self, namespace: &NamespaceId, policy: DownloadPolicy ) -> Result<()>
Set the download policy for a namespace.
sourcepub fn get_download_policy(
&mut self,
namespace: &NamespaceId
) -> Result<DownloadPolicy>
pub fn get_download_policy( &mut self, namespace: &NamespaceId ) -> Result<DownloadPolicy>
Get the download policy for a namespace.
Trait Implementations§
source§impl DownloadPolicyStore for Store
impl DownloadPolicyStore for Store
source§fn get_download_policy(
&mut self,
namespace: &NamespaceId
) -> Result<DownloadPolicy>
fn get_download_policy( &mut self, namespace: &NamespaceId ) -> Result<DownloadPolicy>
source§impl PublicKeyStore for Store
impl PublicKeyStore for Store
source§fn public_key(&self, id: &[u8; 32]) -> Result<VerifyingKey, SignatureError>
fn public_key(&self, id: &[u8; 32]) -> Result<VerifyingKey, SignatureError>
VerifyingKey
]. Read moresource§fn namespace_key(
&self,
bytes: &NamespaceId
) -> Result<NamespacePublicKey, SignatureError>
fn namespace_key( &self, bytes: &NamespaceId ) -> Result<NamespacePublicKey, SignatureError>
Auto Trait Implementations§
impl Freeze for Store
impl !RefUnwindSafe for Store
impl Send for Store
impl Sync for Store
impl Unpin for Store
impl !UnwindSafe for Store
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.