feat: Implement some convenient accessors for custom settings

This commit is contained in:
Clément Renault 2019-05-23 15:36:28 +02:00
parent ce61c16dbe
commit 6f258f71d5
No known key found for this signature in database
GPG Key ID: 0151CDAB43460DAE

View File

@ -1,13 +1,22 @@
use std::sync::Arc; use std::sync::Arc;
use std::ops::Deref; use rocksdb::DBVector;
#[derive(Clone)] #[derive(Clone)]
pub struct CustomSettings(pub Arc<rocksdb::DB>, pub String); pub struct CustomSettings(pub Arc<rocksdb::DB>, pub String);
impl Deref for CustomSettings { impl CustomSettings {
type Target = rocksdb::DB; pub fn set<K, V>(&self, key: K, value: V) -> Result<(), rocksdb::Error>
where K: AsRef<[u8]>,
V: AsRef<[u8]>,
{
let cf = self.0.cf_handle(&self.1).unwrap();
self.0.put_cf(cf, key, value)
}
fn deref(&self) -> &Self::Target { pub fn get<K, V>(&self, key: K) -> Result<Option<DBVector>, rocksdb::Error>
&self.0 where K: AsRef<[u8]>,
{
let cf = self.0.cf_handle(&self.1).unwrap();
self.0.get_cf(cf, key)
} }
} }