Refactor Readable trait (#3309)

Currently Writable accepts trait Write as a type parameter but Readable
takes Read as a trait object, which is not symmetrical and also less performant. This PR changes Readable trait and all places where it's used
This commit is contained in:
hashmap
2020-04-30 17:42:19 +02:00
committed by GitHub
parent 9e51e86538
commit a82041d0ed
20 changed files with 98 additions and 100 deletions
+1 -1
View File
@@ -233,7 +233,7 @@ impl Readable for BitmapChunk {
/// Reading is not currently supported, just return an empty one for now.
/// We store the underlying roaring bitmap externally for the bitmap accumulator
/// and the "hash only" backend means we never actually read these chunks.
fn read(_reader: &mut dyn Reader) -> Result<BitmapChunk, ser::Error> {
fn read<R: Reader>(_reader: &mut R) -> Result<BitmapChunk, ser::Error> {
Ok(BitmapChunk::new())
}
}
+2 -2
View File
@@ -312,7 +312,7 @@ pub struct CommitPos {
}
impl Readable for CommitPos {
fn read(reader: &mut dyn Reader) -> Result<CommitPos, ser::Error> {
fn read<R: Reader>(reader: &mut R) -> Result<CommitPos, ser::Error> {
let pos = reader.read_u64()?;
let height = reader.read_u64()?;
Ok(CommitPos { pos, height })
@@ -384,7 +384,7 @@ impl ser::Writeable for Tip {
}
impl ser::Readable for Tip {
fn read(reader: &mut dyn ser::Reader) -> Result<Tip, ser::Error> {
fn read<R: ser::Reader>(reader: &mut R) -> Result<Tip, ser::Error> {
let height = reader.read_u64()?;
let last = Hash::read(reader)?;
let prev = Hash::read(reader)?;