nostrdb-rs

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

config.rs (1203B)


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