chore: use #[non_exhaustive] instead of private unit field (#3320)

This commit is contained in:
Taiki Endo
2020-12-23 22:48:33 +09:00
committed by GitHub
parent 0deaeb8494
commit 575938d457
15 changed files with 43 additions and 55 deletions
+3 -8
View File
@@ -24,7 +24,8 @@ pin_project! {
/// Error returned by `Timeout`.
#[derive(Debug, PartialEq)]
pub struct Elapsed(());
#[non_exhaustive]
pub struct Elapsed;
impl<S: Stream> Timeout<S> {
pub(super) fn new(stream: S, duration: Duration) -> Self {
@@ -61,7 +62,7 @@ impl<S: Stream> Stream for Timeout<S> {
if *me.poll_deadline {
ready!(me.deadline.poll(cx));
*me.poll_deadline = false;
return Poll::Ready(Some(Err(Elapsed::new())));
return Poll::Ready(Some(Err(Elapsed)));
}
Poll::Pending
@@ -74,12 +75,6 @@ impl<S: Stream> Stream for Timeout<S> {
// ===== impl Elapsed =====
impl Elapsed {
pub(crate) fn new() -> Self {
Elapsed(())
}
}
impl fmt::Display for Elapsed {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
"deadline has elapsed".fmt(fmt)