pub struct Prefixed<M: CoreMem> {
pub prefix: Vec<u8>,
/* private fields */
}Expand description
A “sub” Hyperbee, which can be used for grouping data. When inserted keyss are automatically prefixed
with Prefixed::prefix.
Fields§
§prefix: Vec<u8>All keys inserted with Prefixed::put are prefixed with this value
Implementations§
source§impl<M: CoreMem> Prefixed<M>
impl<M: CoreMem> Prefixed<M>
pub fn new(prefix: &[u8], tree: Arc<RwLock<Tree<M>>>) -> Self
sourcepub async fn get(
&self,
key: &[u8]
) -> Result<Option<(u64, Option<Vec<u8>>)>, HyperbeeError>
pub async fn get( &self, key: &[u8] ) -> Result<Option<(u64, Option<Vec<u8>>)>, HyperbeeError>
Get the value corresponding to the provided key from the Hyperbee
§Errors
When Hyperbee.get_root fails
sourcepub async fn put(
&self,
key: &[u8],
value: Option<&[u8]>
) -> Result<(Option<u64>, u64), HyperbeeError>
pub async fn put( &self, key: &[u8], value: Option<&[u8]> ) -> Result<(Option<u64>, u64), HyperbeeError>
Insert the given key and value into the tree
Returs the seq of the new key, and Option<u64> which contains the seq of the old key
if it was replaced.
sourcepub async fn put_compare_and_swap(
&self,
key: &[u8],
value: Option<&[u8]>,
cas: impl FnOnce(Option<&KeyValueData>, &KeyValueData) -> bool
) -> Result<(Option<u64>, Option<u64>), HyperbeeError>
pub async fn put_compare_and_swap( &self, key: &[u8], value: Option<&[u8]>, cas: impl FnOnce(Option<&KeyValueData>, &KeyValueData) -> bool ) -> Result<(Option<u64>, Option<u64>), HyperbeeError>
Like Prefixed::put but takes a compare_and_swap function.
The compared_and_swap function is called with the old key (if present), and the new key.
The new key is only inserted if compare_and_swap returns true.
Returs two Option<u64>s. The first is the old key, the second is the new key.
sourcepub async fn del(&self, key: &[u8]) -> Result<Option<u64>, HyperbeeError>
pub async fn del(&self, key: &[u8]) -> Result<Option<u64>, HyperbeeError>
Delete the given key from the tree
Returns the seq from the key if it was deleted.
sourcepub async fn del_compare_and_swap(
&self,
key: &[u8],
cas: impl FnOnce(&KeyValueData) -> bool
) -> Result<Option<(bool, u64)>, HyperbeeError>
pub async fn del_compare_and_swap( &self, key: &[u8], cas: impl FnOnce(&KeyValueData) -> bool ) -> Result<Option<(bool, u64)>, HyperbeeError>
Like Prefixed::del but takes a compare_and_swap function.
Before deleting the function is called with existing key’s KeyValueData.
The key is only deleted if compare_and_swap returs true.
Returns the bool representing the result of compare_and_swap, and the seq for the
key.
sourcepub async fn traverse<'a>(
&self,
conf: &TraverseConfig
) -> Result<Traverse<'a, M>, HyperbeeError>
pub async fn traverse<'a>( &self, conf: &TraverseConfig ) -> Result<Traverse<'a, M>, HyperbeeError>
Travese prefixed keys. If you provide TraverseConfig::min_value or
TraverseConfig::max_value it should not include the prefix.