diff --git a/src/de/read.rs b/src/de/read.rs index c22ee23..e2d64eb 100644 --- a/src/de/read.rs +++ b/src/de/read.rs @@ -4,7 +4,7 @@ use serde_crate as serde; /// A byte-oriented reading trait that is specialized for /// slices and generic readers. -pub trait BincodeRead<'storage>: IoRead { +pub trait BincodeRead<'storage>: IoRead + ::private::Sealed { #[doc(hidden)] fn forward_read_str(&mut self, length: usize, visitor: V) -> Result where V: serde::de::Visitor<'storage>; diff --git a/src/internal.rs b/src/internal.rs index 140af99..2090ab8 100644 --- a/src/internal.rs +++ b/src/internal.rs @@ -5,7 +5,7 @@ use std::io::{Write, Read}; use std::io::Error as IoError; use std::{error, fmt, result}; -use ::SizeLimit; +use ::{CountSize, SizeLimit}; use byteorder::{ByteOrder}; pub use super::de::{ @@ -155,12 +155,6 @@ pub fn serialize(value: &T, size_limit: S) -> Result> Ok(writer) } - -struct CountSize { - total: u64, - limit: Option, -} - impl SizeLimit for CountSize { fn add(&mut self, c: u64) -> Result<()> { self.total += c; diff --git a/src/lib.rs b/src/lib.rs index f4d7681..d825f13 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -125,7 +125,7 @@ pub fn serialize(value: &T, size_limit: S) -> internal::Result Result<()>; @@ -143,6 +143,11 @@ pub struct Bounded(pub u64); #[derive(Copy, Clone)] pub struct Infinite; +struct CountSize { + total: u64, + limit: Option, +} + impl SizeLimit for Bounded { #[inline(always)] fn add(&mut self, n: u64) -> Result<()> { @@ -165,3 +170,13 @@ impl SizeLimit for Infinite { #[inline(always)] fn limit(&self) -> Option { None } } + +mod private { + pub trait Sealed {} + + impl<'a> Sealed for super::de::read::SliceReader<'a> {} + impl Sealed for super::de::read::IoReadReader {} + impl Sealed for super::Infinite {} + impl Sealed for super::Bounded {} + impl Sealed for super::CountSize {} +}