Internal type names (#199)
* Remove internal type names from api * Rename IoReadReader to IoReader
This commit is contained in:
parent
e70bfc023b
commit
34aba9acbe
|
|
@ -1,10 +1,10 @@
|
||||||
use std::io::{Read as IoRead, Result as IoResult, Error as IoError, ErrorKind as IoErrorKind};
|
use std::io;
|
||||||
use ::Result;
|
use ::Result;
|
||||||
use serde_crate as serde;
|
use serde_crate as serde;
|
||||||
|
|
||||||
/// A byte-oriented reading trait that is specialized for
|
/// A byte-oriented reading trait that is specialized for
|
||||||
/// slices and generic readers.
|
/// slices and generic readers.
|
||||||
pub trait BincodeRead<'storage>: IoRead + ::private::Sealed {
|
pub trait BincodeRead<'storage>: io::Read + ::private::Sealed {
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
fn forward_read_str<V>(&mut self, length: usize, visitor: V) -> Result<V::Value>
|
fn forward_read_str<V>(&mut self, length: usize, visitor: V) -> Result<V::Value>
|
||||||
where V: serde::de::Visitor<'storage>;
|
where V: serde::de::Visitor<'storage>;
|
||||||
|
|
@ -23,7 +23,7 @@ pub struct SliceReader<'storage> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A BincodeRead implementation for io::Readers
|
/// A BincodeRead implementation for io::Readers
|
||||||
pub struct IoReadReader<R> {
|
pub struct IoReader<R> {
|
||||||
reader: R,
|
reader: R,
|
||||||
temp_buffer: Vec<u8>,
|
temp_buffer: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
@ -37,31 +37,31 @@ impl <'storage> SliceReader<'storage> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <R> IoReadReader<R> {
|
impl <R> IoReader<R> {
|
||||||
/// Constructs an IoReadReader
|
/// Constructs an IoReadReader
|
||||||
pub fn new(r: R) -> IoReadReader<R> {
|
pub fn new(r: R) -> IoReader<R> {
|
||||||
IoReadReader {
|
IoReader {
|
||||||
reader: r,
|
reader: r,
|
||||||
temp_buffer: vec![],
|
temp_buffer: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <'storage> IoRead for SliceReader<'storage> {
|
impl <'storage> io::Read for SliceReader<'storage> {
|
||||||
fn read(&mut self, out: & mut [u8]) -> IoResult<usize> {
|
fn read(&mut self, out: & mut [u8]) -> io::Result<usize> {
|
||||||
(&mut self.slice).read(out)
|
(&mut self.slice).read(out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <R: IoRead> IoRead for IoReadReader<R> {
|
impl <R: io::Read> io::Read for IoReader<R> {
|
||||||
fn read(&mut self, out: & mut [u8]) -> IoResult<usize> {
|
fn read(&mut self, out: & mut [u8]) -> io::Result<usize> {
|
||||||
self.reader.read(out)
|
self.reader.read(out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <'storage> SliceReader<'storage> {
|
impl <'storage> SliceReader<'storage> {
|
||||||
fn unexpected_eof() -> Box<::ErrorKind> {
|
fn unexpected_eof() -> Box<::ErrorKind> {
|
||||||
return Box::new(::ErrorKind::Io(IoError::new(IoErrorKind::UnexpectedEof, "")));
|
return Box::new(::ErrorKind::Io(io::Error::new(io::ErrorKind::UnexpectedEof, "")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -107,7 +107,7 @@ impl <'storage> BincodeRead<'storage> for SliceReader<'storage> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <R> IoReadReader<R> where R: IoRead {
|
impl <R> IoReader<R> where R: io::Read {
|
||||||
fn fill_buffer(&mut self, length: usize) -> Result<()> {
|
fn fill_buffer(&mut self, length: usize) -> Result<()> {
|
||||||
let current_length = self.temp_buffer.len();
|
let current_length = self.temp_buffer.len();
|
||||||
if length > current_length{
|
if length > current_length{
|
||||||
|
|
@ -120,7 +120,7 @@ impl <R> IoReadReader<R> where R: IoRead {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl <R> BincodeRead<'static> for IoReadReader<R> where R: IoRead {
|
impl <R> BincodeRead<'static> for IoReader<R> where R: io::Read {
|
||||||
fn forward_read_str<V>(&mut self, length: usize, visitor: V) -> Result<V::Value>
|
fn forward_read_str<V>(&mut self, length: usize, visitor: V) -> Result<V::Value>
|
||||||
where V: serde::de::Visitor<'static> {
|
where V: serde::de::Visitor<'static> {
|
||||||
self.fill_buffer(length)?;
|
self.fill_buffer(length)?;
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,7 @@
|
||||||
//! that use the `serde` crate for the serializable and deserializable
|
//! that use the `serde` crate for the serializable and deserializable
|
||||||
//! implementation.
|
//! implementation.
|
||||||
|
|
||||||
use std::io::{Write, Read};
|
use std::io::{self, Write, Read};
|
||||||
use std::io::Error as IoError;
|
|
||||||
use std::{error, fmt, result};
|
use std::{error, fmt, result};
|
||||||
use ::{CountSize, SizeLimit};
|
use ::{CountSize, SizeLimit};
|
||||||
use byteorder::{ByteOrder};
|
use byteorder::{ByteOrder};
|
||||||
|
|
@ -34,7 +33,7 @@ pub type Error = Box<ErrorKind>;
|
||||||
pub enum ErrorKind {
|
pub enum ErrorKind {
|
||||||
/// If the error stems from the reader/writer that is being used
|
/// If the error stems from the reader/writer that is being used
|
||||||
/// during (de)serialization, that error will be stored and returned here.
|
/// during (de)serialization, that error will be stored and returned here.
|
||||||
Io(IoError),
|
Io(io::Error),
|
||||||
/// If the bytes in the reader are not decodable because of an invalid
|
/// If the bytes in the reader are not decodable because of an invalid
|
||||||
/// encoding, this error will be returned. This error is only possible
|
/// encoding, this error will be returned. This error is only possible
|
||||||
/// if a stream is corrupted. A stream produced from `encode` or `encode_into`
|
/// if a stream is corrupted. A stream produced from `encode` or `encode_into`
|
||||||
|
|
@ -77,8 +76,8 @@ impl error::Error for ErrorKind {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<IoError> for Error {
|
impl From<io::Error> for Error {
|
||||||
fn from(err: IoError) -> Error {
|
fn from(err: io::Error) -> Error {
|
||||||
ErrorKind::Io(err).into()
|
ErrorKind::Io(err).into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -216,7 +215,7 @@ pub fn serialized_size_bounded<T: ?Sized>(value: &T, max: u64) -> Option<u64>
|
||||||
pub fn deserialize_from<R: ?Sized, T, S, E>(reader: &mut R, size_limit: S) -> Result<T>
|
pub fn deserialize_from<R: ?Sized, T, S, E>(reader: &mut R, size_limit: S) -> Result<T>
|
||||||
where R: Read, T: serde::de::DeserializeOwned, S: SizeLimit, E: ByteOrder
|
where R: Read, T: serde::de::DeserializeOwned, S: SizeLimit, E: ByteOrder
|
||||||
{
|
{
|
||||||
let reader = ::de::read::IoReadReader::new(reader);
|
let reader = ::de::read::IoReader::new(reader);
|
||||||
let mut deserializer = Deserializer::<_, S, E>::new(reader, size_limit);
|
let mut deserializer = Deserializer::<_, S, E>::new(reader, size_limit);
|
||||||
serde::Deserialize::deserialize(&mut deserializer)
|
serde::Deserialize::deserialize(&mut deserializer)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ pub mod internal;
|
||||||
|
|
||||||
pub mod read_types {
|
pub mod read_types {
|
||||||
//! The types that the deserializer uses for optimizations
|
//! The types that the deserializer uses for optimizations
|
||||||
pub use ::de::read::{SliceReader, BincodeRead, IoReadReader};
|
pub use ::de::read::{SliceReader, BincodeRead, IoReader};
|
||||||
}
|
}
|
||||||
|
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
|
@ -175,7 +175,7 @@ mod private {
|
||||||
pub trait Sealed {}
|
pub trait Sealed {}
|
||||||
|
|
||||||
impl<'a> Sealed for super::de::read::SliceReader<'a> {}
|
impl<'a> Sealed for super::de::read::SliceReader<'a> {}
|
||||||
impl<R> Sealed for super::de::read::IoReadReader<R> {}
|
impl<R> Sealed for super::de::read::IoReader<R> {}
|
||||||
impl Sealed for super::Infinite {}
|
impl Sealed for super::Infinite {}
|
||||||
impl Sealed for super::Bounded {}
|
impl Sealed for super::Bounded {}
|
||||||
impl Sealed for super::CountSize {}
|
impl Sealed for super::CountSize {}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue