File: error.rs

package info (click to toggle)
rust-rust-decimal 1.8.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 348 kB
  • sloc: makefile: 2
file content (33 lines) | stat: -rw-r--r-- 765 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use alloc::string::String;
use core::fmt;

/// Error type for the library.
#[derive(Clone, Debug)]
pub struct Error {
    message: String,
}

impl Error {
    /// Instantiate an error with the specified error message.
    ///
    /// This function is only available within the crate as there should never
    /// be a need to create this error outside of the library.
    pub(crate) fn new<S: Into<String>>(message: S) -> Error {
        Error {
            message: message.into(),
        }
    }
}

#[cfg(feature = "std")]
impl std::error::Error for Error {
    fn description(&self) -> &str {
        &self.message
    }
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
        f.pad(&self.message)
    }
}