[−][src]Struct mhdb::Db
The database object. All interraction with mhdb databases is done through this object.
See crate documentation for examples.
Implementations
impl Db
[src]
pub fn open(name: &str) -> Result<Db, Error>
[src]
Open a database, creating the files <name>.dir and <name>.pag unless they already exist.
Errors
open
may return an error if an I/O error is encountered.
pub fn with_sources(
pagsrc: Box<dyn Source>,
dirsrc: Box<dyn Source>
) -> Result<Db, Error>
[src]
pagsrc: Box<dyn Source>,
dirsrc: Box<dyn Source>
) -> Result<Db, Error>
Return a database using the provided sources for storing database content.
Any type implementing Source
can be provided as source.
pub fn store(&mut self, key: impl Datum, val: impl Datum) -> Result<(), Error>
[src]
Store a key in the database.
Any type implementing Datum
may be provided as key
and val
.
Datum
is implemented on any type implementing Serialize
and
Deserialize
.
Errors
If converting the key or value to bytes fails, or if the key-value pair is larger than 506B, an error variant will be returned.
pub fn fetch<T: Datum>(&mut self, key: impl Datum) -> Result<Option<T>, Error>
[src]
Fetch a key from the database. If the key doesn't exist None is returned instead.
The value is deserialized before it is returned. The database doesn't remember types, and apart from checking that deserialization doesn't fail, no type checking is performed.
The following two examples may therefore return a value, without errors, but only one would be correct:
let key = "myint".to_owned(); let num: Option<u64> = db.fetch(key)?;
let key = "myint".to_owned(); let num: Option<f64> = db.fetch(key)?;
Errors
If converting the key to bytes fails, an error variant will be returned.
pub fn delete(&mut self, key: impl Datum) -> Result<bool, Error>
[src]
Delete a key from the database.
If the key doesn't exist false is returned.
Errors
If converting the key to bytes fails, an error variant will be returned.
pub fn contains(&mut self, key: impl Datum) -> Result<bool, Error>
[src]
Check if a key exists in the database.
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,