Commit 97696ec1 authored by Hero Bird's avatar Hero Bird

[pdsl_core] Implement Flush for storage::{Value, Vec, HashMap, Stash}

parent 577e9645
......@@ -332,7 +332,7 @@ impl<T> parity_codec::Decode for SyncCell<T> {
impl<T> Flush for SyncCell<T>
where
T: parity_codec::Codec,
T: parity_codec::Encode,
{
fn flush(&mut self) {
if self.cache.is_dirty() {
......
......@@ -19,6 +19,7 @@ use crate::storage::{
chunk::SyncChunk,
Setup,
Allocator,
Flush,
};
use crate::hash;
......@@ -85,6 +86,17 @@ impl<K, V> Setup for HashMap<K, V> {
}
}
impl<K, V> Flush for HashMap<K, V>
where
K: parity_codec::Encode,
V: parity_codec::Encode,
{
fn flush(&mut self) {
self.len.flush();
self.entries.flush();
}
}
impl<K, V> parity_codec::Encode for HashMap<K, V> {
fn encode_to<W: parity_codec::Output>(&self, dest: &mut W) {
self.len.encode_to(dest);
......
......@@ -19,6 +19,7 @@ use crate::storage::{
Key,
chunk::SyncChunk,
Allocator,
Flush,
};
use parity_codec::{Encode, Decode};
......@@ -74,6 +75,18 @@ impl<'a, T> Values<'a, T> {
}
}
impl<T> Flush for Stash<T>
where
T: parity_codec::Encode,
{
fn flush(&mut self) {
self.next_vacant.flush();
self.len.flush();
self.max_len.flush();
self.entries.flush();
}
}
impl<'a, T> Iterator for Values<'a, T>
where
T: parity_codec::Codec
......
......@@ -19,6 +19,7 @@ use crate::{
self,
chunk::SyncChunk,
Allocator,
Flush,
},
};
......@@ -71,6 +72,16 @@ impl<'a, T> Iter<'a, T> {
}
}
impl<T> Flush for Vec<T>
where
T: parity_codec::Encode,
{
fn flush(&mut self) {
self.len.flush();
self.cells.flush();
}
}
impl<'a, T> Iterator for Iter<'a, T>
where
T: parity_codec::Codec
......
......@@ -138,7 +138,7 @@ where
impl<T> Flush for Value<T>
where
T: parity_codec::Codec + Unpin,
T: parity_codec::Encode + Unpin,
{
fn flush(&mut self) {
self.cell.flush()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment