nostr-rs-relay

My dev fork of nostr-rs-relay
git clone git://jb55.com/nostr-rs-relay
Log | Files | Refs | README | LICENSE

notice.rs (976B)


      1 use crate::error;
      2 
      3 pub enum EventResultStatus {
      4     Saved,
      5     Duplicate,
      6     Error(String),
      7 }
      8 
      9 pub struct EventResult {
     10     pub id: String,
     11     pub status: EventResultStatus,
     12 }
     13 
     14 pub enum Notice {
     15     Message(String),
     16     EventResult(EventResult),
     17 }
     18 
     19 impl Notice {
     20     pub fn err(err: error::Error, id: String) -> Notice {
     21         Notice::err_msg(format!("{}", err), id)
     22     }
     23 
     24     pub fn message(msg: String) -> Notice {
     25         Notice::Message(msg)
     26     }
     27 
     28     pub fn saved(id: String) -> Notice {
     29         Notice::EventResult(EventResult {
     30             id,
     31             status: EventResultStatus::Saved,
     32         })
     33     }
     34 
     35     pub fn duplicate(id: String) -> Notice {
     36         Notice::EventResult(EventResult {
     37             id,
     38             status: EventResultStatus::Duplicate,
     39         })
     40     }
     41 
     42     pub fn err_msg(msg: String, id: String) -> Notice {
     43         Notice::EventResult(EventResult {
     44             id,
     45             status: EventResultStatus::Error(msg),
     46         })
     47     }
     48 }