From 6f258f71d590a257a2713dd447b82dad627a6328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 23 May 2019 15:36:28 +0200 Subject: [PATCH] feat: Implement some convenient accessors for custom settings --- meilidb-data/src/database/custom_settings.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/meilidb-data/src/database/custom_settings.rs b/meilidb-data/src/database/custom_settings.rs index b9227d0bb..112d1b327 100644 --- a/meilidb-data/src/database/custom_settings.rs +++ b/meilidb-data/src/database/custom_settings.rs @@ -1,13 +1,22 @@ use std::sync::Arc; -use std::ops::Deref; +use rocksdb::DBVector; #[derive(Clone)] pub struct CustomSettings(pub Arc, pub String); -impl Deref for CustomSettings { - type Target = rocksdb::DB; +impl CustomSettings { + pub fn set(&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 { - &self.0 + pub fn get(&self, key: K) -> Result, rocksdb::Error> + where K: AsRef<[u8]>, + { + let cf = self.0.cf_handle(&self.1).unwrap(); + self.0.get_cf(cf, key) } }