serde_xrpl/
error.rs

1use std;
2use std::fmt::{self, Display};
3use std::num::ParseIntError;
4
5use serde::{de, ser};
6
7pub type Result<T> = std::result::Result<T, Error>;
8
9// This is a bare-bones implementation. A real library would provide additional
10// information in its error type, for example the line and column at which the
11// error occurred, the byte offset into the input, or the current key being
12// processed.
13#[derive(Clone, Debug, PartialEq)]
14pub enum Error {
15    // One or more variants that can be created by data structures through the
16    // `ser::Error` and `de::Error` traits. For example the Serialize impl for
17    // Mutex<T> might return an error because the mutex is poisoned, or the
18    // Deserialize impl for a struct may return an error because a required
19    // field is missing.
20    Message(String),
21
22    UnknownFieldName(String),
23
24    UnknownFieldType(String),
25
26    InvalidAddress,
27
28    InvalidAmount(ParseIntError, String),
29    InvalidIssuedCurrencyAmount(String),
30
31    InvalidTransactionType(String),
32}
33
34impl ser::Error for Error {
35    fn custom<T: Display>(msg: T) -> Self {
36        Error::Message(msg.to_string())
37    }
38}
39
40impl de::Error for Error {
41    fn custom<T: Display>(msg: T) -> Self {
42        Error::Message(msg.to_string())
43    }
44}
45
46impl Display for Error {
47    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
48        match self {
49            _ => write!(formatter, "{:?}", self),
50        }
51    }
52}
53
54impl std::error::Error for Error {}