Struct hyperbee::Hyperbee

source ·
pub struct Hyperbee<M: CoreMem> { /* private fields */ }
Expand description

An append only B-Tree built on Hypercore. It provides a key-value store API, with methods for inserting, getting, and deleting key-value pair. As well as creating sorted iterators, and “sub” B-Trees for grouping related data.

Implementations§

source§

impl<M: CoreMem> Hyperbee<M>

source

pub async fn version(&self) -> u64

The number of blocks in the hypercore. The first block is always the header block so: version would be the seq of the next block version - 1 is most recent block

source

pub async fn get_root( &self, ensure_header: bool ) -> Result<Option<Arc<RwLock<Node<M>>>>, HyperbeeError>

Gets the root of the tree. When ensure_header == true write the hyperbee header onto the hypercore if it does not exist.

source

pub async fn create_header( &self, metadata: Option<Metadata> ) -> Result<AppendOutcome, HyperbeeError>

Create the header for the Hyperbee. This must be done before writing anything else to the tree.

source

pub async fn print(&self) -> Result<String, HyperbeeError>

Returs a string representing the structure of the tree showing the keys in each node

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 Hyperbee::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 Hyperbee::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 fn sub(&self, prefix: &[u8]) -> Prefixed<M>

Create a new tree with all it’s operation’s prefixed by the provided prefix.

source

pub async fn traverse<'a>( &self, conf: TraverseConfig ) -> Result<Traverse<'a, M>, HyperbeeError>

Traverse the tree based on the given TraverseConfig

source§

impl Hyperbee<RandomAccessDisk>

source

pub async fn from_storage_dir<T: AsRef<Path>>( path_to_storage_dir: T ) -> Result<Hyperbee<RandomAccessDisk>, HyperbeeError>

Helper for creating a Hyperbee

§Panics

when storage path is incorrect when Hypercore failse to build when Blocks fails to build

§Errors

when Hyperbee fails to build

source§

impl Hyperbee<RandomAccessMemory>

source

pub async fn from_ram() -> Result<Hyperbee<RandomAccessMemory>, HyperbeeError>

Helper for creating a Hyperbee in RAM

Trait Implementations§

source§

impl<M: Debug + CoreMem> Debug for Hyperbee<M>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<M> !RefUnwindSafe for Hyperbee<M>

§

impl<M> Send for Hyperbee<M>

§

impl<M> Sync for Hyperbee<M>

§

impl<M> Unpin for Hyperbee<M>

§

impl<M> !UnwindSafe for Hyperbee<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