pub struct PrefixTrie { /* private fields */ }
Expand description
A prefix trie implementation that stores its nodes in TiKV.
The trie uses a prefix string to namespace its nodes in the TiKV keyspace, preventing conflicts with other data stored in the same TiKV cluster.
Try to not be comedic and nameclash with structures with a Store derive, as unexpected things might happen.
Implementations§
Source§impl PrefixTrie
impl PrefixTrie
Sourcepub fn new(prefix: impl Into<String>) -> Self
pub fn new(prefix: impl Into<String>) -> Self
Creates a new prefix trie with the given namespace prefix.
§Examples
let trie = PrefixTrie::new("my_namespace");
Sourcepub async fn insert(
&self,
txn: &mut Transaction,
key: &str,
) -> Result<(), TikvError>
pub async fn insert( &self, txn: &mut Transaction, key: &str, ) -> Result<(), TikvError>
Inserts a key into the trie.
Empty strings are not allowed as keys.
§Errors
Returns an error if the key is empty or if the TiKV operation fails.
Sourcepub async fn get(
&self,
txn: &mut Transaction,
key: &str,
) -> Result<Option<String>, TikvError>
pub async fn get( &self, txn: &mut Transaction, key: &str, ) -> Result<Option<String>, TikvError>
Retrieves a key from the trie.
Returns None
if the key doesn’t exist.
Sourcepub async fn find_by_prefix(
&self,
txn: &mut Transaction,
prefix: &str,
) -> Result<Vec<String>, TikvError>
pub async fn find_by_prefix( &self, txn: &mut Transaction, prefix: &str, ) -> Result<Vec<String>, TikvError>
Finds all keys in the trie that start with the given prefix.
Returns a vector of matching keys in no particular order.
Trait Implementations§
Source§impl Clone for PrefixTrie
impl Clone for PrefixTrie
Source§fn clone(&self) -> PrefixTrie
fn clone(&self) -> PrefixTrie
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for PrefixTrie
impl RefUnwindSafe for PrefixTrie
impl Send for PrefixTrie
impl Sync for PrefixTrie
impl Unpin for PrefixTrie
impl UnwindSafe for PrefixTrie
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)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>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T
in a tonic::Request