summaryrefslogtreecommitdiffstats
path: root/third_party/rust/scroll/src/error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/scroll/src/error.rs')
-rw-r--r--third_party/rust/scroll/src/error.rs26
1 files changed, 12 insertions, 14 deletions
diff --git a/third_party/rust/scroll/src/error.rs b/third_party/rust/scroll/src/error.rs
index 7740254774..1b68c2e4c7 100644
--- a/third_party/rust/scroll/src/error.rs
+++ b/third_party/rust/scroll/src/error.rs
@@ -1,10 +1,7 @@
use core::fmt::{self, Display};
use core::result;
-
-#[cfg(feature = "std")]
-use std::error;
#[cfg(feature = "std")]
-use std::io;
+use std::{error, io};
#[derive(Debug)]
/// A custom Scroll error
@@ -20,18 +17,19 @@ pub enum Error {
size: usize,
msg: &'static str,
},
+ /// A custom Scroll error for reporting messages to clients.
+ /// For no-std, use [`Error::BadInput`] with a static string.
#[cfg(feature = "std")]
- /// A custom Scroll error for reporting messages to clients
Custom(String),
- #[cfg(feature = "std")]
/// Returned when IO based errors are encountered
+ #[cfg(feature = "std")]
IO(io::Error),
}
#[cfg(feature = "std")]
impl error::Error for Error {
fn description(&self) -> &str {
- match *self {
+ match self {
Error::TooBig { .. } => "TooBig",
Error::BadOffset(_) => "BadOffset",
Error::BadInput { .. } => "BadInput",
@@ -40,7 +38,7 @@ impl error::Error for Error {
}
}
fn cause(&self) -> Option<&dyn error::Error> {
- match *self {
+ match self {
Error::TooBig { .. } => None,
Error::BadOffset(_) => None,
Error::BadInput { .. } => None,
@@ -59,23 +57,23 @@ impl From<io::Error> for Error {
impl Display for Error {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
- match *self {
+ match self {
Error::TooBig { ref size, ref len } => {
- write!(fmt, "type is too big ({}) for {}", size, len)
+ write!(fmt, "type is too big ({size}) for {len}")
}
Error::BadOffset(ref offset) => {
- write!(fmt, "bad offset {}", offset)
+ write!(fmt, "bad offset {offset}")
}
Error::BadInput { ref msg, ref size } => {
- write!(fmt, "bad input {} ({})", msg, size)
+ write!(fmt, "bad input {msg} ({size})")
}
#[cfg(feature = "std")]
Error::Custom(ref msg) => {
- write!(fmt, "{}", msg)
+ write!(fmt, "{msg}")
}
#[cfg(feature = "std")]
Error::IO(ref err) => {
- write!(fmt, "{}", err)
+ write!(fmt, "{err}")
}
}
}