diff --git a/README.md b/README.md index 440fc68..39061c4 100644 --- a/README.md +++ b/README.md @@ -26,19 +26,19 @@ Features - Simple To Use, Fast, Secure - Threadsafe -- Key/Value Storage -- bincode or yaml storage +- ron, bincode, or yaml storage Usage ----- Usage is quite simple: -- Create/open a database using `Database::open` - - You can specify the kind of Key you want using this Syntax: - `Database::::open` -- `Insert`/`Retrieve` data from the Database -- Don't forget to run `flush` periodically +- Create/open a database using one of the Database constructors: + - Create a `FileDatabase` with `FileDatabase::from_path` + - Create a `MemoryDatabase` with `MemoryDatabase::memory` + - Create a `Database` with `Database::from_parts` +- `Write`/`Read` data from the Database +- Don't forget to run `sync` periodically ```rust # use std::collections::HashMap; @@ -88,14 +88,6 @@ default-features = false features = ["ron_enc"] ``` -How it works ------------- - -Internally the Database holds a Hashmap behind a RwLock. -This Hashmap is then written to/read from and safely casted to the requested -type. This works thanks to encoding/decoding traits. - - [doc]:http://neikos.me/rustbreak/rustbreak/index.html [Daybreak]:https://propublica.github.io/daybreak/ diff --git a/src/lib.rs b/src/lib.rs index 3738537..88d91f5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -164,6 +164,22 @@ impl Database backend.put_data(ser.as_bytes())?; Ok(()) } + + /// Create a database from its constituents + pub fn from_parts(data: Data, backend: Back, deser: DeSer) -> Database { + Database { + data: RwLock::new(data), + backend: Mutex::new(backend), + deser: deser, + } + } + + /// Break a database into its individual parts + pub fn into_inner(self) -> error::Result<(Data, Back, DeSer)> { + Ok((self.data.into_inner().map_err(|_| error::RustbreakErrorKind::PoisonError)?, + self.backend.into_inner().map_err(|_| error::RustbreakErrorKind::PoisonError)?, + self.deser)) + } } /// A database backed by a file