tangle_indexer


git clone https://radroots.dev/git/tangle_indexer.git
Log | Files | Refs | Submodules | LICENSE

mod.rs (1337B)


      1 pub mod comment;
      2 pub mod follow;
      3 pub mod job_feedback;
      4 pub mod job_request;
      5 pub mod job_result;
      6 pub mod listing;
      7 pub mod post;
      8 pub mod profile;
      9 pub mod reaction;
     10 
     11 pub use comment::ToRadrootsCommentEventIndex;
     12 pub use follow::ToRadrootsFollowEventIndex;
     13 pub use job_feedback::ToRadrootsJobFeedbackEventIndex;
     14 pub use job_request::ToRadrootsJobRequestEventIndex;
     15 pub use job_result::ToRadrootsJobResultEventIndex;
     16 pub use listing::ToRadrootsListingEventIndex;
     17 pub use post::ToRadrootsPostEventIndex;
     18 pub use profile::ToRadrootsProfileEventIndex;
     19 pub use reaction::ToRadrootsReactionEventIndex;
     20 
     21 #[macro_export]
     22 macro_rules! opt_required {
     23     ($opt:expr) => {
     24         $opt.required(stringify!($opt))
     25     };
     26 }
     27 
     28 #[macro_export]
     29 macro_rules! opt_default {
     30     ($opt:expr) => {
     31         match $opt {
     32             Some(val) => val,
     33             None => "".to_string(),
     34         }
     35     };
     36     ($opt:expr, $default:expr) => {
     37         match $opt {
     38             Some(val) => val,
     39             None => $default.to_string(),
     40         }
     41     };
     42 }
     43 
     44 pub trait RequiredField {
     45     type Output;
     46     fn required(self, field_name: &str) -> Result<Self::Output, String>;
     47 }
     48 
     49 impl<T> RequiredField for Option<T> {
     50     type Output = T;
     51 
     52     fn required(self, field_name: &str) -> Result<T, String> {
     53         self.ok_or_else(|| format!("Missing {}", field_name))
     54     }
     55 }