Files
continuwuity/src/database/util.rs
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

29 lines
780 B
Rust
Raw Normal View History

use conduit::{err, Result};
2024-08-08 17:18:30 +00:00
use rocksdb::{Direction, IteratorMode};
#[inline]
pub(crate) fn _into_direction(mode: &IteratorMode<'_>) -> Direction {
use Direction::{Forward, Reverse};
use IteratorMode::{End, From, Start};
match mode {
Start | From(_, Forward) => Forward,
End | From(_, Reverse) => Reverse,
}
}
2024-05-28 06:59:50 +00:00
#[inline]
pub(crate) fn result<T>(r: std::result::Result<T, rocksdb::Error>) -> Result<T, conduit::Error> {
r.map_or_else(or_else, and_then)
}
#[inline(always)]
pub(crate) fn and_then<T>(t: T) -> Result<T, conduit::Error> { Ok(t) }
pub(crate) fn or_else<T>(e: rocksdb::Error) -> Result<T, conduit::Error> { Err(map_err(e)) }
pub(crate) fn map_err(e: rocksdb::Error) -> conduit::Error {
let string = e.into_string();
err!(Database(error!("{string}")))
}