mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-07 00:00:08 +02:00
chore: Revert "use #[non_exhaustive] instead of private unit field" (#3323)
This reverts commit 575938d457.
This commit is contained in:
@@ -224,13 +224,12 @@ mod date {
|
|||||||
|
|
||||||
use time::{self, Duration};
|
use time::{self, Duration};
|
||||||
|
|
||||||
#[non_exhaustive]
|
pub struct Now(());
|
||||||
pub struct Now;
|
|
||||||
|
|
||||||
/// Returns a struct, which when formatted, renders an appropriate `Date`
|
/// Returns a struct, which when formatted, renders an appropriate `Date`
|
||||||
/// header value.
|
/// header value.
|
||||||
pub fn now() -> Now {
|
pub fn now() -> Now {
|
||||||
Now
|
Now(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gee Alex, doesn't this seem like premature optimization. Well you see
|
// Gee Alex, doesn't this seem like premature optimization. Well you see
|
||||||
|
|||||||
@@ -24,8 +24,7 @@ pin_project! {
|
|||||||
|
|
||||||
/// Error returned by `Timeout`.
|
/// Error returned by `Timeout`.
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
#[non_exhaustive]
|
pub struct Elapsed(());
|
||||||
pub struct Elapsed;
|
|
||||||
|
|
||||||
impl<S: Stream> Timeout<S> {
|
impl<S: Stream> Timeout<S> {
|
||||||
pub(super) fn new(stream: S, duration: Duration) -> Self {
|
pub(super) fn new(stream: S, duration: Duration) -> Self {
|
||||||
@@ -62,7 +61,7 @@ impl<S: Stream> Stream for Timeout<S> {
|
|||||||
if *me.poll_deadline {
|
if *me.poll_deadline {
|
||||||
ready!(me.deadline.poll(cx));
|
ready!(me.deadline.poll(cx));
|
||||||
*me.poll_deadline = false;
|
*me.poll_deadline = false;
|
||||||
return Poll::Ready(Some(Err(Elapsed)));
|
return Poll::Ready(Some(Err(Elapsed::new())));
|
||||||
}
|
}
|
||||||
|
|
||||||
Poll::Pending
|
Poll::Pending
|
||||||
@@ -75,6 +74,12 @@ impl<S: Stream> Stream for Timeout<S> {
|
|||||||
|
|
||||||
// ===== impl Elapsed =====
|
// ===== impl Elapsed =====
|
||||||
|
|
||||||
|
impl Elapsed {
|
||||||
|
pub(crate) fn new() -> Self {
|
||||||
|
Elapsed(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl fmt::Display for Elapsed {
|
impl fmt::Display for Elapsed {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
"deadline has elapsed".fmt(fmt)
|
"deadline has elapsed".fmt(fmt)
|
||||||
|
|||||||
@@ -42,13 +42,12 @@ use std::io;
|
|||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Default)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Default)]
|
||||||
#[non_exhaustive]
|
pub struct BytesCodec(());
|
||||||
pub struct BytesCodec;
|
|
||||||
|
|
||||||
impl BytesCodec {
|
impl BytesCodec {
|
||||||
/// Creates a new `BytesCodec` for shipping around raw bytes.
|
/// Creates a new `BytesCodec` for shipping around raw bytes.
|
||||||
pub fn new() -> BytesCodec {
|
pub fn new() -> BytesCodec {
|
||||||
BytesCodec
|
BytesCodec(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -219,6 +219,7 @@ impl<T, U> Framed<T, U> {
|
|||||||
codec: self.inner.codec,
|
codec: self.inner.codec,
|
||||||
read_buf: self.inner.state.read.buffer,
|
read_buf: self.inner.state.read.buffer,
|
||||||
write_buf: self.inner.state.write.buffer,
|
write_buf: self.inner.state.write.buffer,
|
||||||
|
_priv: (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -281,7 +282,7 @@ where
|
|||||||
///
|
///
|
||||||
/// [`Framed`]: crate::codec::Framed
|
/// [`Framed`]: crate::codec::Framed
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[non_exhaustive]
|
#[allow(clippy::manual_non_exhaustive)]
|
||||||
pub struct FramedParts<T, U> {
|
pub struct FramedParts<T, U> {
|
||||||
/// The inner transport used to read bytes to and write bytes to
|
/// The inner transport used to read bytes to and write bytes to
|
||||||
pub io: T,
|
pub io: T,
|
||||||
@@ -294,6 +295,10 @@ pub struct FramedParts<T, U> {
|
|||||||
|
|
||||||
/// A buffer with unprocessed data which are not written yet.
|
/// A buffer with unprocessed data which are not written yet.
|
||||||
pub write_buf: BytesMut,
|
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> {
|
impl<T, U> FramedParts<T, U> {
|
||||||
@@ -307,6 +312,7 @@ impl<T, U> FramedParts<T, U> {
|
|||||||
codec,
|
codec,
|
||||||
read_buf: BytesMut::new(),
|
read_buf: BytesMut::new(),
|
||||||
write_buf: BytesMut::new(),
|
write_buf: BytesMut::new(),
|
||||||
|
_priv: (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -409,8 +409,9 @@ pub struct Builder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// An error when the number of bytes read is more than max frame length.
|
/// 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.
|
/// 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 {
|
if n > self.builder.max_frame_len as u64 {
|
||||||
return Err(io::Error::new(
|
return Err(io::Error::new(
|
||||||
io::ErrorKind::InvalidData,
|
io::ErrorKind::InvalidData,
|
||||||
LengthDelimitedCodecError,
|
LengthDelimitedCodecError { _priv: () },
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -585,7 +586,7 @@ impl Encoder<Bytes> for LengthDelimitedCodec {
|
|||||||
if n > self.builder.max_frame_len {
|
if n > self.builder.max_frame_len {
|
||||||
return Err(io::Error::new(
|
return Err(io::Error::new(
|
||||||
io::ErrorKind::InvalidInput,
|
io::ErrorKind::InvalidInput,
|
||||||
LengthDelimitedCodecError,
|
LengthDelimitedCodecError { _priv: () },
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -530,7 +530,7 @@ impl<'a, Inner: AsRawFd> AsyncFdReadyGuard<'a, Inner> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Err(err) if err.kind() == io::ErrorKind::WouldBlock => Err(TryIoError),
|
Err(err) if err.kind() == io::ErrorKind::WouldBlock => Err(TryIoError(())),
|
||||||
result => Ok(result),
|
result => Ok(result),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -591,7 +591,7 @@ impl<'a, Inner: AsRawFd> AsyncFdReadyMutGuard<'a, Inner> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Err(err) if err.kind() == io::ErrorKind::WouldBlock => Err(TryIoError),
|
Err(err) if err.kind() == io::ErrorKind::WouldBlock => Err(TryIoError(())),
|
||||||
result => Ok(result),
|
result => Ok(result),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -620,5 +620,4 @@ impl<'a, T: std::fmt::Debug + AsRawFd> std::fmt::Debug for AsyncFdReadyMutGuard<
|
|||||||
/// [`WouldBlock`]: std::io::ErrorKind::WouldBlock
|
/// [`WouldBlock`]: std::io::ErrorKind::WouldBlock
|
||||||
/// [`try_io`]: method@AsyncFdReadyGuard::try_io
|
/// [`try_io`]: method@AsyncFdReadyGuard::try_io
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[non_exhaustive]
|
pub struct TryIoError(());
|
||||||
pub struct TryIoError;
|
|
||||||
|
|||||||
@@ -15,8 +15,9 @@ cfg_io_util! {
|
|||||||
///
|
///
|
||||||
/// [`empty`]: fn@empty
|
/// [`empty`]: fn@empty
|
||||||
/// [std]: std::io::empty
|
/// [std]: std::io::empty
|
||||||
#[non_exhaustive]
|
pub struct Empty {
|
||||||
pub struct Empty;
|
_p: (),
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates a new empty async reader.
|
/// Creates a new empty async reader.
|
||||||
///
|
///
|
||||||
@@ -41,7 +42,7 @@ cfg_io_util! {
|
|||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn empty() -> Empty {
|
pub fn empty() -> Empty {
|
||||||
Empty
|
Empty { _p: () }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,9 @@ cfg_io_util! {
|
|||||||
///
|
///
|
||||||
/// [sink]: sink()
|
/// [sink]: sink()
|
||||||
/// [std]: std::io::Sink
|
/// [std]: std::io::Sink
|
||||||
#[non_exhaustive]
|
pub struct Sink {
|
||||||
pub struct Sink;
|
_p: (),
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates an instance of an async writer which will successfully consume all
|
/// Creates an instance of an async writer which will successfully consume all
|
||||||
/// data.
|
/// data.
|
||||||
@@ -44,7 +45,7 @@ cfg_io_util! {
|
|||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn sink() -> Sink {
|
pub fn sink() -> Sink {
|
||||||
Sink
|
Sink { _p: () }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ impl Handle {
|
|||||||
///
|
///
|
||||||
/// Contrary to `current`, this never panics
|
/// Contrary to `current`, this never panics
|
||||||
pub fn try_current() -> Result<Self, TryCurrentError> {
|
pub fn try_current() -> Result<Self, TryCurrentError> {
|
||||||
context::current().ok_or(TryCurrentError)
|
context::current().ok_or(TryCurrentError(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Spawn a future onto the Tokio runtime.
|
/// Spawn a future onto the Tokio runtime.
|
||||||
@@ -203,8 +203,7 @@ impl Handle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Error returned by `try_current` when no Runtime has been started
|
/// Error returned by `try_current` when no Runtime has been started
|
||||||
#[non_exhaustive]
|
pub struct TryCurrentError(());
|
||||||
pub struct TryCurrentError;
|
|
||||||
|
|
||||||
impl fmt::Debug for TryCurrentError {
|
impl fmt::Debug for TryCurrentError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ pub enum TryAcquireError {
|
|||||||
/// The semaphore has no available permits.
|
/// The semaphore has no available permits.
|
||||||
NoPermits,
|
NoPermits,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Error returned from the [`Semaphore::acquire`] function.
|
/// Error returned from the [`Semaphore::acquire`] function.
|
||||||
///
|
///
|
||||||
/// An `acquire` operation can only fail if the semaphore has been
|
/// An `acquire` operation can only fail if the semaphore has been
|
||||||
@@ -63,8 +62,7 @@ pub enum TryAcquireError {
|
|||||||
/// [closed]: crate::sync::Semaphore::close
|
/// [closed]: crate::sync::Semaphore::close
|
||||||
/// [`Semaphore::acquire`]: crate::sync::Semaphore::acquire
|
/// [`Semaphore::acquire`]: crate::sync::Semaphore::acquire
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[non_exhaustive]
|
pub struct AcquireError(());
|
||||||
pub struct AcquireError;
|
|
||||||
|
|
||||||
pub(crate) struct Acquire<'a> {
|
pub(crate) struct Acquire<'a> {
|
||||||
node: Waiter,
|
node: Waiter,
|
||||||
@@ -523,7 +521,7 @@ unsafe impl Sync for Acquire<'_> {}
|
|||||||
|
|
||||||
impl AcquireError {
|
impl AcquireError {
|
||||||
fn closed() -> AcquireError {
|
fn closed() -> AcquireError {
|
||||||
AcquireError
|
AcquireError(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,8 +55,7 @@ impl<T> From<SendError<T>> for TrySendError<T> {
|
|||||||
|
|
||||||
/// Error returned by `Receiver`.
|
/// Error returned by `Receiver`.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[non_exhaustive]
|
pub struct RecvError(());
|
||||||
pub struct RecvError;
|
|
||||||
|
|
||||||
impl fmt::Display for RecvError {
|
impl fmt::Display for RecvError {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
|||||||
@@ -167,8 +167,7 @@ unsafe impl<T> Sync for OwnedMutexGuard<T> where T: ?Sized + Send + Sync {}
|
|||||||
///
|
///
|
||||||
/// [`Mutex::try_lock`]: Mutex::try_lock
|
/// [`Mutex::try_lock`]: Mutex::try_lock
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[non_exhaustive]
|
pub struct TryLockError(());
|
||||||
pub struct TryLockError;
|
|
||||||
|
|
||||||
impl fmt::Display for TryLockError {
|
impl fmt::Display for TryLockError {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
@@ -324,7 +323,7 @@ impl<T: ?Sized> Mutex<T> {
|
|||||||
pub fn try_lock(&self) -> Result<MutexGuard<'_, T>, TryLockError> {
|
pub fn try_lock(&self) -> Result<MutexGuard<'_, T>, TryLockError> {
|
||||||
match self.s.try_acquire(1) {
|
match self.s.try_acquire(1) {
|
||||||
Ok(_) => Ok(MutexGuard { lock: self }),
|
Ok(_) => Ok(MutexGuard { lock: self }),
|
||||||
Err(_) => Err(TryLockError),
|
Err(_) => Err(TryLockError(())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -379,7 +378,7 @@ impl<T: ?Sized> Mutex<T> {
|
|||||||
pub fn try_lock_owned(self: Arc<Self>) -> Result<OwnedMutexGuard<T>, TryLockError> {
|
pub fn try_lock_owned(self: Arc<Self>) -> Result<OwnedMutexGuard<T>, TryLockError> {
|
||||||
match self.s.try_acquire(1) {
|
match self.s.try_acquire(1) {
|
||||||
Ok(_) => Ok(OwnedMutexGuard { lock: self }),
|
Ok(_) => Ok(OwnedMutexGuard { lock: self }),
|
||||||
Err(_) => Err(TryLockError),
|
Err(_) => Err(TryLockError(())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ impl<T: 'static> LocalKey<T> {
|
|||||||
if let Some(val) = v.borrow().as_ref() {
|
if let Some(val) = v.borrow().as_ref() {
|
||||||
Ok(f(val))
|
Ok(f(val))
|
||||||
} else {
|
} else {
|
||||||
Err(AccessError)
|
Err(AccessError { _private: () })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -223,8 +223,9 @@ impl<T: 'static> StaticLifetime for T {}
|
|||||||
|
|
||||||
/// An error returned by [`LocalKey::try_with`](method@LocalKey::try_with).
|
/// An error returned by [`LocalKey::try_with`](method@LocalKey::try_with).
|
||||||
#[derive(Clone, Copy, Eq, PartialEq)]
|
#[derive(Clone, Copy, Eq, PartialEq)]
|
||||||
#[non_exhaustive]
|
pub struct AccessError {
|
||||||
pub struct AccessError;
|
_private: (),
|
||||||
|
}
|
||||||
|
|
||||||
impl fmt::Debug for AccessError {
|
impl fmt::Debug for AccessError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
|||||||
@@ -42,8 +42,7 @@ impl From<Kind> for Error {
|
|||||||
|
|
||||||
/// Error returned by `Timeout`.
|
/// Error returned by `Timeout`.
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
#[non_exhaustive]
|
pub struct Elapsed(());
|
||||||
pub struct Elapsed;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) enum InsertError {
|
pub(crate) enum InsertError {
|
||||||
@@ -100,6 +99,12 @@ impl fmt::Display for Error {
|
|||||||
|
|
||||||
// ===== impl Elapsed =====
|
// ===== impl Elapsed =====
|
||||||
|
|
||||||
|
impl Elapsed {
|
||||||
|
pub(crate) fn new() -> Self {
|
||||||
|
Elapsed(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl fmt::Display for Elapsed {
|
impl fmt::Display for Elapsed {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
"deadline has elapsed".fmt(fmt)
|
"deadline has elapsed".fmt(fmt)
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ where
|
|||||||
|
|
||||||
// Now check the timer
|
// Now check the timer
|
||||||
match me.delay.poll(cx) {
|
match me.delay.poll(cx) {
|
||||||
Poll::Ready(()) => Poll::Ready(Err(Elapsed)),
|
Poll::Ready(()) => Poll::Ready(Err(Elapsed::new())),
|
||||||
Poll::Pending => Poll::Pending,
|
Poll::Pending => Poll::Pending,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user