enostr

rust nostr lib that works on the web and natively
git clone git://jb55.com/enostr
Log | Files | Refs

error.rs (962B)


      1 use serde_json;
      2 
      3 #[derive(Debug)]
      4 pub enum Error {
      5     MessageEmpty,
      6     MessageDecodeFailed,
      7     InvalidSignature,
      8     Json(serde_json::Error),
      9     Generic(String),
     10 }
     11 
     12 impl std::cmp::PartialEq for Error {
     13     fn eq(&self, other: &Self) -> bool {
     14         match (self, other) {
     15             (Error::MessageEmpty, Error::MessageEmpty) => true,
     16             (Error::MessageDecodeFailed, Error::MessageDecodeFailed) => true,
     17             (Error::InvalidSignature, Error::InvalidSignature) => true,
     18             // This is slightly wrong but whatevs
     19             (Error::Json(..), Error::Json(..)) => true,
     20             (Error::Generic(left), Error::Generic(right)) => left == right,
     21             _ => false,
     22         }
     23     }
     24 }
     25 
     26 impl std::cmp::Eq for Error {}
     27 
     28 impl From<String> for Error {
     29     fn from(s: String) -> Self {
     30         Error::Generic(s)
     31     }
     32 }
     33 
     34 impl From<serde_json::Error> for Error {
     35     fn from(e: serde_json::Error) -> Self {
     36         Error::Json(e)
     37     }
     38 }