use crate::Error; /// Mix-in trait for loading values from LMDB that may or may not exist. pub trait TxnOptional { fn optional(self) -> Result, E>; } impl TxnOptional for Result { fn optional(self) -> Result, Error> { match self { Ok(x) => Ok(Some(x)), Err(lmdb::Error::NotFound) => Ok(None), Err(e) => Err(e.into()), } } } /// Transform a transaction that would fail with a `MapFull` error into an optional result. pub trait TxnMapFull { fn allow_map_full(self) -> Result, E>; } impl TxnMapFull for Result { fn allow_map_full(self) -> Result, Error> { match self { Ok(x) => Ok(Some(x)), Err(Error::DatabaseError(lmdb::Error::MapFull)) => Ok(None), Err(e) => Err(e), } } }