radrootsd

JSON-RPC bridge for Radroots event publishing
git clone https://radroots.dev/git/radrootsd.git
Log | Files | Refs | README | LICENSE

registry.rs (572B)


      1 #![forbid(unsafe_code)]
      2 
      3 use std::sync::{Arc, RwLock};
      4 
      5 #[derive(Clone, Default)]
      6 pub struct MethodRegistry {
      7     inner: Arc<RwLock<Vec<String>>>,
      8 }
      9 
     10 impl MethodRegistry {
     11     pub fn track(&self, name: &'static str) {
     12         let mut methods = self.inner.write().unwrap_or_else(|e| e.into_inner());
     13         if methods.iter().any(|entry| entry == name) {
     14             return;
     15         }
     16         methods.push(name.to_string());
     17         methods.sort();
     18     }
     19 
     20     pub fn list(&self) -> Vec<String> {
     21         self.inner.read().unwrap_or_else(|e| e.into_inner()).clone()
     22     }
     23 }