Rename generic writer

This commit is contained in:
James Dyson 2019-01-21 13:32:48 +00:00
parent 6ca24956ad
commit 9933ed6b1f
4 changed files with 9 additions and 8 deletions

View File

@ -4,7 +4,7 @@ use sehn::*;
fn main() { fn main() {
let mut buf = [0u8; 2048]; 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); let mut s = BaseSerializer::new(&mut w);
s.serialize_unit("hello", 1.0).unwrap(); s.serialize_unit("hello", 1.0).unwrap();

View File

@ -85,6 +85,7 @@ impl<'a> GenericWriteBuffer for SliceBuffer<'a> {
#[cfg(any(feature = "std", feature = "alloc"))] #[cfg(any(feature = "std", feature = "alloc"))]
impl GenericWriteBuffer for Vec<u8> { impl GenericWriteBuffer for Vec<u8> {
// TODO: Use never type
type Error = (); type Error = ();
#[inline] #[inline]

View File

@ -11,7 +11,7 @@ pub use self::buffer::*;
pub fn to_string<T>(value: T) -> Result<String, SerializerError<()>> pub fn to_string<T>(value: T) -> Result<String, SerializerError<()>>
where T: Serialize where T: Serialize
{ {
let mut w = GenericWriter::from(Vec::new()); let mut w = GenericBufferWriter::from(Vec::new());
let mut s = BaseSerializer::new(&mut w); let mut s = BaseSerializer::new(&mut w);
value.serialize(&mut s)?; value.serialize(&mut s)?;
Ok(w.to_string()) Ok(w.to_string())

View File

@ -1,21 +1,21 @@
use crate::se::*; use crate::se::*;
use super::{GenericWriteBuffer, GenericReadBuffer}; use super::{GenericWriteBuffer, GenericReadBuffer};
pub struct GenericWriter<T> pub struct GenericBufferWriter<T>
where T: GenericWriteBuffer where T: GenericWriteBuffer + GenericReadBuffer
{ {
buf: T buf: T
} }
impl<T> From<T> for GenericWriter<T> impl<T> From<T> for GenericBufferWriter<T>
where T: GenericWriteBuffer where T: GenericWriteBuffer + GenericReadBuffer
{ {
fn from(buf: T) -> Self { fn from(buf: T) -> Self {
Self { buf } Self { buf }
} }
} }
impl<T> GenericWriter<T> impl<T> GenericBufferWriter<T>
where T: GenericWriteBuffer + GenericReadBuffer where T: GenericWriteBuffer + GenericReadBuffer
{ {
pub fn into_inner(self) -> T { pub fn into_inner(self) -> T {
@ -36,7 +36,7 @@ impl<T> GenericWriter<T>
} }
} }
impl<T> Write for &mut GenericWriter<T> impl<T> Write for &mut GenericBufferWriter<T>
where where
T: GenericWriteBuffer + GenericReadBuffer, T: GenericWriteBuffer + GenericReadBuffer,
T::Error: WriteError T::Error: WriteError