nostrdb-rs

nostrdb in rust!
git clone git://jb55.com/nostrdb-rs
Log | Files | Refs | Submodules | README | LICENSE

config.rs (1359B)


      1 use crate::bindings;
      2 
      3 pub struct Config {
      4     pub config: bindings::ndb_config,
      5 }
      6 
      7 impl Default for Config {
      8     fn default() -> Self {
      9         Config::new()
     10     }
     11 }
     12 
     13 impl Config {
     14     pub fn new() -> Self {
     15         let mut config = bindings::ndb_config {
     16             filter_context: std::ptr::null_mut(),
     17             sub_cb: None,
     18             sub_cb_ctx: std::ptr::null_mut(),
     19             ingest_filter: None,
     20             flags: 0,
     21             ingester_threads: 0,
     22             mapsize: 0,
     23         };
     24 
     25         unsafe {
     26             bindings::ndb_default_config(&mut config);
     27         }
     28 
     29         Config { config }
     30     }
     31 
     32     //
     33     pub fn set_flags(&mut self, flags: i32) -> &mut Self {
     34         self.config.flags = flags;
     35         self
     36     }
     37 
     38     pub fn skip_validation(&mut self, skip: bool) -> &mut Self {
     39         let skip_note_verify: i32 = 1 << 1;
     40 
     41         if skip {
     42             self.config.flags |= skip_note_verify;
     43         } else {
     44             self.config.flags &= !skip_note_verify;
     45         }
     46 
     47         self
     48     }
     49 
     50     pub fn set_ingester_threads(&mut self, threads: i32) -> &mut Self {
     51         self.config.ingester_threads = threads;
     52         self
     53     }
     54 
     55     // Add other setter methods as needed
     56 
     57     // Internal method to get a raw pointer to the config, used in Ndb
     58     pub fn as_ptr(&self) -> *const bindings::ndb_config {
     59         &self.config
     60     }
     61 }