Enum jammdb::Data

source ·
pub enum Data<'b, 'tx> {
    Bucket(BucketName<'b, 'tx>),
    KeyValue(KVPair<'b, 'tx>),
}
Expand description

Key / Value or Bucket Data

The two enum variants represent either a key / value pair or a nested bucket. If you want to access the underneath data, you must match the variant first.

Examples

use jammdb::{DB, Data};

let db = DB::open("my.db")?;
let mut tx = db.tx(true)?;
let bucket = tx.create_bucket("my-bucket")?;

if let Some(data) = bucket.get("my-key") {
    match data {
        Data::Bucket(b) => assert_eq!(b.name(), b"my-key"),
        Data::KeyValue(kv) => assert_eq!(kv.key(), b"my-key"),
    }
}

Variants§

§

Bucket(BucketName<'b, 'tx>)

Contains data about a nested bucket

§

KeyValue(KVPair<'b, 'tx>)

a key / value pair of bytes

Implementations§

source§

impl<'b, 'tx> Data<'b, 'tx>

source

pub fn is_kv(&self) -> bool

Checks if the Data is a KVPair

source

pub fn kv(&self) -> &KVPair<'_, '_>

Asserts that the Data is a KVPair and returns the inner data

Panics if the data is a Bucket.

source

pub fn key(&self) -> &[u8]

Trait Implementations§

source§

impl<'b, 'tx> Clone for Data<'b, 'tx>

source§

fn clone(&self) -> Data<'b, 'tx>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'b, 'tx> Debug for Data<'b, 'tx>

source§

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

Formats the value using the given formatter. Read more
source§

impl<'b, 'tx> PartialEq for Data<'b, 'tx>

source§

fn eq(&self, other: &Data<'b, 'tx>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'b, 'tx> Eq for Data<'b, 'tx>

source§

impl<'b, 'tx> StructuralEq for Data<'b, 'tx>

source§

impl<'b, 'tx> StructuralPartialEq for Data<'b, 'tx>

Auto Trait Implementations§

§

impl<'b, 'tx> RefUnwindSafe for Data<'b, 'tx>

§

impl<'b, 'tx> !Send for Data<'b, 'tx>

§

impl<'b, 'tx> !Sync for Data<'b, 'tx>

§

impl<'b, 'tx> Unpin for Data<'b, 'tx>

§

impl<'b, 'tx> UnwindSafe for Data<'b, 'tx>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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, U> Into<U> for Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.