chore: Revert "use #[non_exhaustive] instead of private unit field" (#3323)

This reverts commit 575938d457.
This commit is contained in:
Taiki Endo
2020-12-23 08:27:58 -08:00
committed by GitHub
parent 575938d457
commit ce0e9c67cf
15 changed files with 55 additions and 43 deletions
+2 -3
View File
@@ -42,13 +42,12 @@ use std::io;
/// ```
///
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Default)]
#[non_exhaustive]
pub struct BytesCodec;
pub struct BytesCodec(());
impl BytesCodec {
/// Creates a new `BytesCodec` for shipping around raw bytes.
pub fn new() -> BytesCodec {
BytesCodec
BytesCodec(())
}
}
+7 -1
View File
@@ -219,6 +219,7 @@ impl<T, U> Framed<T, U> {
codec: self.inner.codec,
read_buf: self.inner.state.read.buffer,
write_buf: self.inner.state.write.buffer,
_priv: (),
}
}
}
@@ -281,7 +282,7 @@ where
///
/// [`Framed`]: crate::codec::Framed
#[derive(Debug)]
#[non_exhaustive]
#[allow(clippy::manual_non_exhaustive)]
pub struct FramedParts<T, U> {
/// The inner transport used to read bytes to and write bytes to
pub io: T,
@@ -294,6 +295,10 @@ pub struct FramedParts<T, U> {
/// A buffer with unprocessed data which are not written yet.
pub write_buf: BytesMut,
/// This private field allows us to add additional fields in the future in a
/// backwards compatible way.
_priv: (),
}
impl<T, U> FramedParts<T, U> {
@@ -307,6 +312,7 @@ impl<T, U> FramedParts<T, U> {
codec,
read_buf: BytesMut::new(),
write_buf: BytesMut::new(),
_priv: (),
}
}
}
+5 -4
View File
@@ -409,8 +409,9 @@ pub struct Builder {
}
/// An error when the number of bytes read is more than max frame length.
#[non_exhaustive]
pub struct LengthDelimitedCodecError;
pub struct LengthDelimitedCodecError {
_priv: (),
}
/// A codec for frames delimited by a frame head specifying their lengths.
///
@@ -495,7 +496,7 @@ impl LengthDelimitedCodec {
if n > self.builder.max_frame_len as u64 {
return Err(io::Error::new(
io::ErrorKind::InvalidData,
LengthDelimitedCodecError,
LengthDelimitedCodecError { _priv: () },
));
}
@@ -585,7 +586,7 @@ impl Encoder<Bytes> for LengthDelimitedCodec {
if n > self.builder.max_frame_len {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
LengthDelimitedCodecError,
LengthDelimitedCodecError { _priv: () },
));
}