Struct hyperbee::prefixed::Prefixed

source ·
pub struct Prefixed<M: CoreMem> {
    pub prefix: Vec<u8>,
    /* private fields */
}
Expand description

A “sub” Hyperbee, which can be used for grouping data. get, put, del, traverse operations are automatically prefixed with Prefixed::prefix + PrefixedConfig::seperator where appropriate.

Fields§

§prefix: Vec<u8>

All keys inserted with Prefixed::put are prefixed with this value

Implementations§

source§

impl<M: CoreMem> Prefixed<M>

source

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

source

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.

source

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.

source

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.

source

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.

source

pub async fn traverse<'a>( &self, conf: &TraverseConfig ) -> Result<impl Stream<Item = KeyDataResult> + 'a, HyperbeeError>
where M: 'a,

Travese prefixed keys. If you provide TraverseConfig::min_value or TraverseConfig::max_value it should not include the prefix. Note that the key that is yielded has Self::prefix + PrefixedConfig::seperator stripped (which is the same behavior as JavaScript Hyperbee’s method .sub

Auto Trait Implementations§

§

impl<M> !RefUnwindSafe for Prefixed<M>

§

impl<M> Send for Prefixed<M>

§

impl<M> Sync for Prefixed<M>

§

impl<M> Unpin for Prefixed<M>

§

impl<M> !UnwindSafe for Prefixed<M>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more