gflags/
error.rs

1use std::fmt::{self, Display};
2
3/// Error returned when parsing a flag value fails.
4///
5/// This is the error type returned by [`Value::parse`].
6///
7/// [`Value::parse`]: trait.Value.html
8#[derive(Debug)]
9pub struct Error {
10    message: String,
11}
12
13/// Result of parsing a flag value.
14///
15/// This is the result type returned by [`Value::parse`].
16///
17/// [`Value::parse`]: trait.Value.html
18pub type Result<T> = std::result::Result<T, Error>;
19
20impl Error {
21    pub fn new<T: Display>(message: T) -> Self {
22        Error {
23            message: message.to_string(),
24        }
25    }
26}
27
28impl std::error::Error for Error {}
29
30impl Display for Error {
31    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
32        formatter.write_str(&self.message)
33    }
34}
35
36#[doc(hidden)]
37#[allow(non_snake_case)]
38pub fn Error<T: Display>(message: T) -> Error {
39    Error::new(message)
40}