1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
//! A key-value store backed by your local file system. //! //! The underlying hashmap uses an inefficient hashing algorithm to //! place keys and values into large and unoptimized buckets that it //! reads/writes from a file. //! //! The file size is very large, and does not re-allocate memory. //! Also, the hashmap doesn't resize its keyspace. I may or may not //! fix these things.. this project was mostly just to learn Rust. //! //! Reads are something like 2k QPS, writes 500 QPS. It's thread- and //! process-safe (probably). //! //! ## Installation //! //! Add this to your `Cargo.toml`: //! //! ```toml //! [dependencies] //! kvlite = "0.1.2" //! ``` //! //! ## Examples //! //! //! ``` //! extern crate kvlite; //! //! use kvlite::FileHashMap; //! //! let kv = FileHashMap::new("myfile.kvlite"); //! //! kv.insert("foo", "bar"); //! //! let foo = kv.get("foo").unwrap(); //! //! println!("foo: {}", foo); // prints: "foo: bar" //! ``` extern crate nix; pub mod hashmap; mod file; use std::fmt; use std::error; use std::result; pub use hashmap::FileHashMap; /// KVLite Result Type pub type Result<T> = result::Result<T, Error>; /// KVLite Error Type #[derive(Debug, PartialEq)] pub enum Error { IO, NotFound, } impl error::Error for Error { fn description(&self) -> &str { match self { &Error::IO => "i/o error", &Error::NotFound => "key not found", } } } impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { &Error::IO => write!(f, "io error"), &Error::NotFound => write!(f, "not found error"), } } }