mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-04-25 03:02:12 +00:00
add fn size
This commit is contained in:
parent
ecbd044c30
commit
a7d8e21550
@ -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 {
|
||||
type Key: Clone + Send + Debug + AsRef<[u8]> + Borrow<[u8]> + From<Vec<u8>> + Hash + Eq;
|
||||
|
||||
fn size(&self) -> usize;
|
||||
|
||||
fn 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 {
|
||||
type Key = Key;
|
||||
|
||||
fn size(&self) -> usize {
|
||||
self.value.len()
|
||||
}
|
||||
|
||||
fn key(&self) -> &Self::Key {
|
||||
&self.key
|
||||
}
|
||||
|
@ -111,9 +111,9 @@ impl<'a, TRecord: RecordT> RecordStore<'a, TRecord> for MemoryStore<TRecord> {
|
||||
}
|
||||
|
||||
fn put(&'a mut self, r: TRecord) -> Result<()> {
|
||||
// if r.value.len() >= self.config.max_value_bytes {
|
||||
// return Err(Error::ValueTooLarge)
|
||||
// }
|
||||
if r.size() >= self.config.max_value_bytes {
|
||||
return Err(Error::ValueTooLarge)
|
||||
}
|
||||
|
||||
let num_records = self.records.len();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user