add fn size

This commit is contained in:
folex 2020-08-04 20:26:21 +03:00
parent ecbd044c30
commit a7d8e21550
2 changed files with 9 additions and 3 deletions

View File

@ -37,6 +37,8 @@ use std::fmt::Debug;
pub trait RecordT: Eq + Send + Clone + Debug + Into<proto::Record> + TryFrom<proto::Record, Error = io::Error> + 'static { pub trait RecordT: Eq + Send + Clone + Debug + Into<proto::Record> + TryFrom<proto::Record, Error = io::Error> + 'static {
type Key: Clone + Send + Debug + AsRef<[u8]> + Borrow<[u8]> + From<Vec<u8>> + Hash + Eq; type Key: Clone + Send + Debug + AsRef<[u8]> + Borrow<[u8]> + From<Vec<u8>> + Hash + Eq;
fn size(&self) -> usize;
fn key(&self) -> &Self::Key; fn key(&self) -> &Self::Key;
fn into_key(self) -> Self::Key; fn into_key(self) -> Self::Key;
@ -51,6 +53,10 @@ pub trait RecordT: Eq + Send + Clone + Debug + Into<proto::Record> + TryFrom<pro
impl RecordT for Record { impl RecordT for Record {
type Key = Key; type Key = Key;
fn size(&self) -> usize {
self.value.len()
}
fn key(&self) -> &Self::Key { fn key(&self) -> &Self::Key {
&self.key &self.key
} }

View File

@ -111,9 +111,9 @@ impl<'a, TRecord: RecordT> RecordStore<'a, TRecord> for MemoryStore<TRecord> {
} }
fn put(&'a mut self, r: TRecord) -> Result<()> { fn put(&'a mut self, r: TRecord) -> Result<()> {
// if r.value.len() >= self.config.max_value_bytes { if r.size() >= self.config.max_value_bytes {
// return Err(Error::ValueTooLarge) return Err(Error::ValueTooLarge)
// } }
let num_records = self.records.len(); let num_records = self.records.len();