Struct obkv::KvReader

source ·
pub struct KvReader<'a, K> { /* private fields */ }
Expand description

A reader of obkv databases.

Implementations§

source§

impl<'a, K> KvReader<'a, K>

source

pub fn new(bytes: &[u8]) -> KvReader<'_, K>

Construct a reader on top of a memory area.

use obkv::KvReaderU16;

let mut iter = KvReaderU16::new(&[]).iter();
assert_eq!(iter.next(), None);
source

pub fn get(&self, requested_key: K) -> Option<&'a [u8]>where K: Key + PartialOrd,

Returns the value associated with the given key or None if the key is not present.

use obkv::{KvWriterU16, KvReaderU16};

let mut writer = KvWriterU16::memory();
writer.insert(0, b"hello").unwrap();
writer.insert(1, b"blue").unwrap();
writer.insert(255, b"world").unwrap();
let obkv = writer.into_inner().unwrap();

let reader = KvReaderU16::new(&obkv);
assert_eq!(reader.get(0), Some(&b"hello"[..]));
assert_eq!(reader.get(1), Some(&b"blue"[..]));
assert_eq!(reader.get(10), None);
assert_eq!(reader.get(255), Some(&b"world"[..]));
source

pub fn iter(&self) -> Fuse<KvIter<'a, K>>where K: Key,

Returns an iterator over all the keys in the key-value store.

use obkv::{KvWriterU16, KvReaderU16};

let mut writer = KvWriterU16::memory();
writer.insert(0, b"hello").unwrap();
writer.insert(1, b"blue").unwrap();
writer.insert(255, b"world").unwrap();
let obkv = writer.into_inner().unwrap();

let mut iter = KvReaderU16::new(&obkv).iter();
assert_eq!(iter.next(), Some((0, &b"hello"[..])));
assert_eq!(iter.next(), Some((1, &b"blue"[..])));
assert_eq!(iter.next(), Some((255, &b"world"[..])));
assert_eq!(iter.next(), None);
assert_eq!(iter.next(), None); // is it fused?

Trait Implementations§

source§

impl<'a, K: Clone> Clone for KvReader<'a, K>

source§

fn clone(&self) -> KvReader<'a, K>

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<'a, K: Debug> Debug for KvReader<'a, K>

source§

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

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

impl<'a, K: Default> Default for KvReader<'a, K>

source§

fn default() -> KvReader<'a, K>

Returns the “default value” for a type. Read more
source§

impl<'a, K: Hash> Hash for KvReader<'a, K>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'a, K: Key> IntoIterator for KvReader<'a, K>

§

type Item = (K, &'a [u8])

The type of the elements being iterated over.
§

type IntoIter = Fuse<KvIter<'a, K>>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a, K: PartialEq> PartialEq for KvReader<'a, K>

source§

fn eq(&self, other: &KvReader<'a, K>) -> 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<'a, K: Copy> Copy for KvReader<'a, K>

source§

impl<'a, K: Eq> Eq for KvReader<'a, K>

source§

impl<'a, K> StructuralEq for KvReader<'a, K>

source§

impl<'a, K> StructuralPartialEq for KvReader<'a, K>

Auto Trait Implementations§

§

impl<'a, K> RefUnwindSafe for KvReader<'a, K>where K: RefUnwindSafe,

§

impl<'a, K> Send for KvReader<'a, K>where K: Send,

§

impl<'a, K> Sync for KvReader<'a, K>where K: Sync,

§

impl<'a, K> Unpin for KvReader<'a, K>where K: Unpin,

§

impl<'a, K> UnwindSafe for KvReader<'a, K>where K: UnwindSafe,

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> 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.