pub struct Replica<'a, I = Box<ReplicaInfo>> { /* private fields */ }
Expand description
Local representation of a mutable, synchronizable key-value store.
Implementations§
source§impl<'a, I> Replica<'a, I>
impl<'a, I> Replica<'a, I>
sourcepub fn new(store: StoreInstance<'a>, info: I) -> Self
pub fn new(store: StoreInstance<'a>, info: I) -> Self
Create a new replica.
sourcepub fn insert(
&mut self,
key: impl AsRef<[u8]>,
author: &Author,
hash: Hash,
len: u64
) -> Result<usize, InsertError>
pub fn insert( &mut self, key: impl AsRef<[u8]>, author: &Author, hash: Hash, len: u64 ) -> Result<usize, InsertError>
Insert a new record at the given key.
The entry will by signed by the provided author
.
The len
must be the byte length of the data identified by hash
.
Returns the number of entries removed as a consequence of this insertion, or an error either if the entry failed to validate or if a store operation failed.
sourcepub fn delete_prefix(
&mut self,
prefix: impl AsRef<[u8]>,
author: &Author
) -> Result<usize, InsertError>
pub fn delete_prefix( &mut self, prefix: impl AsRef<[u8]>, author: &Author ) -> Result<usize, InsertError>
Delete 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 fn insert_remote_entry(
&mut self,
entry: SignedEntry,
received_from: PeerIdBytes,
content_status: ContentStatus
) -> Result<usize, InsertError>
pub fn insert_remote_entry( &mut self, entry: SignedEntry, received_from: PeerIdBytes, content_status: ContentStatus ) -> Result<usize, InsertError>
Insert an entry into this replica which was received from a remote peer.
This will verify both the namespace and author signatures of the entry, emit an on_insert
event, and insert the entry into the replica store.
Returns the number of entries removed as a consequence of this insertion, or an error if the entry failed to validate or if a store operation failed.
sourcepub fn hash_and_insert(
&mut self,
key: impl AsRef<[u8]>,
author: &Author,
data: impl AsRef<[u8]>
) -> Result<Hash, InsertError>
pub fn hash_and_insert( &mut self, key: impl AsRef<[u8]>, author: &Author, data: impl AsRef<[u8]> ) -> Result<Hash, InsertError>
Hashes the given data and inserts it.
This does not store the content, just the record of it. Returns the calculated hash.
sourcepub fn record_id(
&self,
key: impl AsRef<[u8]>,
author: &Author
) -> RecordIdentifier
pub fn record_id( &self, key: impl AsRef<[u8]>, author: &Author ) -> RecordIdentifier
Get the identifier for an entry in this replica.
sourcepub fn sync_initial_message(&mut self) -> Result<Message<SignedEntry>>
pub fn sync_initial_message(&mut self) -> Result<Message<SignedEntry>>
Create the initial message for the set reconciliation flow with a remote peer.
sourcepub fn sync_process_message(
&mut self,
message: Message<SignedEntry>,
from_peer: PeerIdBytes,
state: &mut SyncOutcome
) -> Result<Option<Message<SignedEntry>>, Error>
pub fn sync_process_message( &mut self, message: Message<SignedEntry>, from_peer: PeerIdBytes, state: &mut SyncOutcome ) -> Result<Option<Message<SignedEntry>>, Error>
Process a set reconciliation message from a remote peer.
Returns the next message to be sent to the peer, if any.
sourcepub fn id(&self) -> NamespaceId
pub fn id(&self) -> NamespaceId
Get the namespace identifier for this Replica
.
sourcepub fn capability(&self) -> &Capability
pub fn capability(&self) -> &Capability
Get the Capability
of this Replica
.
sourcepub fn secret_key(&self) -> Result<&NamespaceSecret, ReadOnly>
pub fn secret_key(&self) -> Result<&NamespaceSecret, ReadOnly>
Get the byte representation of the NamespaceSecret
key for this replica. Will fail if
the replica is read only
Trait Implementations§
Auto Trait Implementations§
impl<'a, I> Freeze for Replica<'a, I>where
I: Freeze,
impl<'a, I = Box<ReplicaInfo>> !RefUnwindSafe for Replica<'a, I>
impl<'a, I> Send for Replica<'a, I>where
I: Send,
impl<'a, I> Sync for Replica<'a, I>where
I: Sync,
impl<'a, I> Unpin for Replica<'a, I>where
I: Unpin,
impl<'a, I = Box<ReplicaInfo>> !UnwindSafe for Replica<'a, I>
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.