mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-05-01 21:52:16 +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 {
|
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
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user