Struct galvanize::reader::Reader [] [src]

pub struct Reader<'a, F: Read + Seek + 'a> { /* fields omitted */ }

Allows you to read from CDB.

Example

Given a file stored at filename with the following contents:

{
    "key": "value",
}

this is how you can read the stored value:

use galvanize::Reader;
use std::fs::File;

let key = "key".as_bytes();

let mut f = try!(File::open(filename));
let mut cdb_reader = try!(Reader::new(&mut f));
let stored_vals = cdb_reader.get(key);
assert_eq!(stored_vals.len(), 1);
assert_eq!(&stored_vals[0][..], &"value".as_bytes()[..]);

// The CDB contains only one entry:
assert_eq!(cdb_reader.len(), 1);

// Accessing a key that isn't in the CDB:
let non_existing_key = "non_existing_key".as_bytes();
let empty = cdb_reader.get(non_existing_key);
assert_eq!(empty.len(), 0);

assert!(cdb_reader.get_first(non_existing_key).is_err());

Methods

impl<'a, F: Read + Seek + 'a> Reader<'a, F>
[src]

Creates a new Reader consuming the provided file.

How many (key, value) pairs are there in this Read Only CDB.

Return a Vec of all the values under the given key.

Return a Vec of all the keys in this Read Only CDB.

Keep in mind that if there're duplicated keys, they will appear multiple times in the resulting Vec.

Pull the value bytes for the first occurence of the given key in this CDB.

Pull the value bytes for the indexst occurence of the given key in this CDB.

impl<'a> Reader<'a, File>
[src]

Transform this Reader into a Writer using the same underlying file.

The underlying file will have its hash table truncated. This will be regenerated on Writer drop.

Trait Implementations

impl<'a, F: Debug + Read + Seek + 'a> Debug for Reader<'a, F>
[src]

Formats the value using the given formatter.

impl<'a, 'file: 'a, F: Read + Seek + 'file> IntoIterator for &'a mut Reader<'file, F>
[src]

Convert a Reader CDB into an Iterator.

One use of this, is using Rust's for loop syntax.

Example

let mut f = File::open(filename).unwrap();

let mut cdb_reader = Reader::new(&mut f).ok().unwrap();
let len = cdb_reader.len();

for (k, v) in cdb_reader.into_iter() {
    // Consume the (k, v) pair.
}

A single key, value pair.

The ItemIterator type this will convert into.

Creates an iterator from a value. Read more