summaryrefslogtreecommitdiffstats
path: root/tokio/src/time/error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tokio/src/time/error.rs')
-rw-r--r--tokio/src/time/error.rs26
1 files changed, 9 insertions, 17 deletions
diff --git a/tokio/src/time/error.rs b/tokio/src/time/error.rs
index 24395c47..8674febe 100644
--- a/tokio/src/time/error.rs
+++ b/tokio/src/time/error.rs
@@ -23,17 +23,23 @@ use std::fmt;
/// way to do this would be dropping the future that issued the timer operation.
///
/// [shed load]: https://en.wikipedia.org/wiki/Load_Shedding
-#[derive(Debug)]
+#[derive(Debug, Copy, Clone)]
pub struct Error(Kind);
-#[derive(Debug, Clone, Copy)]
+#[derive(Debug, Clone, Copy, Eq, PartialEq)]
#[repr(u8)]
-enum Kind {
+pub(crate) enum Kind {
Shutdown = 1,
AtCapacity = 2,
Invalid = 3,
}
+impl From<Kind> for Error {
+ fn from(k: Kind) -> Self {
+ Error(k)
+ }
+}
+
/// Error returned by `Timeout`.
#[derive(Debug, PartialEq)]
pub struct Elapsed(());
@@ -41,7 +47,6 @@ pub struct Elapsed(());
#[derive(Debug)]
pub(crate) enum InsertError {
Elapsed,
- Invalid,
}
// ===== impl Error =====
@@ -76,19 +81,6 @@ impl Error {
pub fn is_invalid(&self) -> bool {
matches!(self.0, Kind::Invalid)
}
-
- pub(crate) fn as_u8(&self) -> u8 {
- self.0 as u8
- }
-
- pub(crate) fn from_u8(n: u8) -> Self {
- Error(match n {
- 1 => Shutdown,
- 2 => AtCapacity,
- 3 => Invalid,
- _ => panic!("u8 does not correspond to any time error variant"),
- })
- }
}
impl error::Error for Error {}