Struct obkv::KvReader[][src]

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

A reader of obkv databases.

Implementations

Construct a reader on top of a memory area.

use obkv::KvReaderU16;

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

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"[..]));

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Feeds this value into the given Hasher. Read more

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

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.