aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2021-11-06 22:25:23 +0100
committerDaniel Schadt <kingdread@gmx.de>2021-11-06 22:25:23 +0100
commit834a2d4f8a7dbd0e9eb14573c4340eb41af04738 (patch)
treebebd06cc13104fb8e77dc313f2f2ee862eb94a32 /src/lib.rs
downloadmodderbaas-834a2d4f8a7dbd0e9eb14573c4340eb41af04738.tar.gz
modderbaas-834a2d4f8a7dbd0e9eb14573c4340eb41af04738.tar.bz2
modderbaas-834a2d4f8a7dbd0e9eb14573c4340eb41af04738.zip
Initial commit
This is the inital commit of a somewhat working version.
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644
index 0000000..f169c82
--- /dev/null
+++ b/src/lib.rs
@@ -0,0 +1,52 @@
+use std::{fs, path::Path};
+
+use log::debug;
+
+macro_rules! regex {
+ ($re:literal $(,)?) => {{
+ static RE: once_cell::sync::OnceCell<regex::Regex> = 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 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<W, P: AsRef<Path>, F: for<'p> Fn(&'p Path) -> Result<W>>(
+ path: P,
+ scanner: F,
+) -> Result<Vec<W>> {
+ 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)
+}