Struct KvReader

Source
pub struct KvReader<K> { /* private fields */ }
Expand description

A reader of obkv databases.

Implementations§

Source§

impl<K> KvReader<K>

Source

pub fn from_slice(bytes: &[u8]) -> &KvReader<K>

Construct a reader on top of a memory area.

use obkv::KvReaderU16;

let reader = KvReaderU16::from_slice(&[][..]);
let mut iter = reader.iter();
assert_eq!(iter.next(), None);
Source

pub fn get(&self, requested_key: K) -> Option<&[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 = obkv[..].into();
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<'_, 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 reader: &KvReaderU16 = obkv[..].into();
let mut iter = reader.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?
Source

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

Converts a KvReader to a byte slice.

Source

pub fn boxed(&self) -> Box<Self>

Converts a KvReader to a boxed KvReader.

Trait Implementations§

Source§

impl<K: Debug> Debug for KvReader<K>

Source§

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

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

impl<'a, K> From<&'a [u8]> for &'a KvReader<K>

Construct a reader on top of a memory area.

use obkv::KvReaderU16;

let reader: &KvReaderU16 = [][..].into();
let mut iter = reader.iter();
assert_eq!(iter.next(), None);
Source§

fn from(bytes: &'a [u8]) -> Self

Converts to this type from the input type.
Source§

impl<K> From<Box<[u8]>> for Box<KvReader<K>>

Construct a reader on top of a memory area.

use obkv::KvReaderU16;

let reader: Box<KvReaderU16> = Vec::new().into_boxed_slice().into();
let mut iter = reader.iter();
assert_eq!(iter.next(), None);
Source§

fn from(boxed_bytes: Box<[u8]>) -> Self

Converts to this type from the input type.
Source§

impl<K: Hash> Hash for KvReader<K>

Source§

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

Feeds this value into the given Hasher. Read more
Source§

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

Source§

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

The type of the elements being iterated over.
Source§

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<K: PartialEq> PartialEq for KvReader<K>

Source§

fn eq(&self, other: &KvReader<K>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<K: Eq> Eq for KvReader<K>

Source§

impl<K> StructuralPartialEq for KvReader<K>

Auto Trait Implementations§

§

impl<K> Freeze for KvReader<K>

§

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

§

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

§

impl<K> !Sized for KvReader<K>

§

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

§

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

§

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

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