use std::{fs, path::Path}; use log::debug; macro_rules! regex { ($re:literal $(,)?) => {{ static RE: once_cell::sync::OnceCell = once_cell::sync::OnceCell::new(); RE.get_or_init(|| regex::Regex::new($re).unwrap()) }}; } pub mod baas; pub mod contentdb; pub mod download; pub mod error; pub mod game; pub mod kvstore; pub mod minemod; pub mod util; pub mod world; pub use baas::{Baas, Snapshot}; pub use contentdb::ContentDb; pub use download::{Downloader, Source}; pub use game::Game; pub use minemod::{MineMod, Modpack}; pub use world::World; use error::Result; /// Scan all files in the given directory. /// /// Files for which `scanner` returns `Ok(..)` will be collected and returned. Files for which /// `scanner` returns `Err(..)` will be silently discarded. /// /// ```rust /// use modderbaas::minemod::MineMod; /// let mods = scan("/tmp", |p| MineMod::open(p))?; /// ``` pub fn scan, F: for<'p> Fn(&'p Path) -> Result>( path: P, scanner: F, ) -> Result> { debug!("Scanning through {:?}", path.as_ref()); let mut good_ones = vec![]; for entry in fs::read_dir(path)? { let entry = entry?; if let Ok(i) = scanner(&entry.path()) { good_ones.push(i); } } Ok(good_ones) }