From 9933ed6b1f5086f694831ce8d87315a1a21376b7 Mon Sep 17 00:00:00 2001 From: James Dyson Date: Mon, 21 Jan 2019 13:32:48 +0000 Subject: [PATCH] Rename generic writer --- sehn/examples/no-std.rs | 2 +- sehn/src/utils/buffer.rs | 1 + sehn/src/utils/mod.rs | 2 +- sehn/src/utils/writer.rs | 12 ++++++------ 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/sehn/examples/no-std.rs b/sehn/examples/no-std.rs index 3bef7af..d6000de 100644 --- a/sehn/examples/no-std.rs +++ b/sehn/examples/no-std.rs @@ -4,7 +4,7 @@ use sehn::*; fn main() { let mut buf = [0u8; 2048]; - let mut w: GenericWriter<_> = SliceBuffer::new(&mut buf).into(); + let mut w: GenericBufferWriter<_> = SliceBuffer::new(&mut buf).into(); let mut s = BaseSerializer::new(&mut w); s.serialize_unit("hello", 1.0).unwrap(); diff --git a/sehn/src/utils/buffer.rs b/sehn/src/utils/buffer.rs index e867296..5160077 100644 --- a/sehn/src/utils/buffer.rs +++ b/sehn/src/utils/buffer.rs @@ -85,6 +85,7 @@ impl<'a> GenericWriteBuffer for SliceBuffer<'a> { #[cfg(any(feature = "std", feature = "alloc"))] impl GenericWriteBuffer for Vec { + // TODO: Use never type type Error = (); #[inline] diff --git a/sehn/src/utils/mod.rs b/sehn/src/utils/mod.rs index a30d3f8..51cd965 100644 --- a/sehn/src/utils/mod.rs +++ b/sehn/src/utils/mod.rs @@ -11,7 +11,7 @@ pub use self::buffer::*; pub fn to_string(value: T) -> Result> where T: Serialize { - let mut w = GenericWriter::from(Vec::new()); + let mut w = GenericBufferWriter::from(Vec::new()); let mut s = BaseSerializer::new(&mut w); value.serialize(&mut s)?; Ok(w.to_string()) diff --git a/sehn/src/utils/writer.rs b/sehn/src/utils/writer.rs index 7b9642b..4a70ba3 100644 --- a/sehn/src/utils/writer.rs +++ b/sehn/src/utils/writer.rs @@ -1,21 +1,21 @@ use crate::se::*; use super::{GenericWriteBuffer, GenericReadBuffer}; -pub struct GenericWriter - where T: GenericWriteBuffer +pub struct GenericBufferWriter + where T: GenericWriteBuffer + GenericReadBuffer { buf: T } -impl From for GenericWriter - where T: GenericWriteBuffer +impl From for GenericBufferWriter + where T: GenericWriteBuffer + GenericReadBuffer { fn from(buf: T) -> Self { Self { buf } } } -impl GenericWriter +impl GenericBufferWriter where T: GenericWriteBuffer + GenericReadBuffer { pub fn into_inner(self) -> T { @@ -36,7 +36,7 @@ impl GenericWriter } } -impl Write for &mut GenericWriter +impl Write for &mut GenericBufferWriter where T: GenericWriteBuffer + GenericReadBuffer, T::Error: WriteError