Skip to main content

sui_core/
error.rs

1use std::error::Error as StdError;
2use std::fmt;
3
4/// A result whose error defaults to SUI's [`Error`]. The error type can be
5/// given too, so a glob import of SUI's prelude leaves `Result<T, E>` working.
6pub type Result<T, E = Error> = std::result::Result<T, E>;
7
8#[derive(Debug, Clone, PartialEq, Eq)]
9pub struct Error {
10    message: String,
11}
12
13impl Error {
14    pub fn new(message: impl Into<String>) -> Self {
15        Self {
16            message: message.into(),
17        }
18    }
19
20    pub fn message(&self) -> &str {
21        &self.message
22    }
23}
24
25impl fmt::Display for Error {
26    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27        f.write_str(self.message())
28    }
29}
30
31impl StdError for Error {}