futilehdl/src/package.rs

38 lines
797 B
Rust
Raw Permalink Normal View History

2022-01-23 20:52:08 +00:00
use std::collections::BTreeMap;
2022-01-23 21:51:39 +00:00
use std::fs::File;
2022-01-23 21:52:06 +00:00
use std::path::PathBuf;
2022-01-23 20:52:08 +00:00
2022-01-23 21:51:39 +00:00
pub struct Package {
2022-01-23 20:52:08 +00:00
name: String,
path: PathBuf,
}
2022-01-23 21:51:39 +00:00
impl Package {
pub fn open(&self) -> Result<File, std::io::Error> {
2022-01-23 23:10:09 +00:00
let filepath = self.path.join("main.hyd");
2022-01-23 21:51:39 +00:00
File::open(filepath)
}
}
pub struct PackageRegistry {
2022-01-23 21:52:06 +00:00
packages: BTreeMap<String, Package>,
2022-01-23 20:52:08 +00:00
}
impl PackageRegistry {
2022-01-23 21:51:39 +00:00
pub fn new() -> Self {
2022-01-23 20:52:08 +00:00
let mut packages = BTreeMap::new();
2022-01-23 21:52:06 +00:00
packages.insert(
"builtins".to_string(),
Package {
name: "builtins".to_string(),
path: "./lib/builtins/".into(),
},
);
2022-01-23 20:52:08 +00:00
Self { packages }
}
2022-01-23 21:51:39 +00:00
pub fn get(&self, name: &str) -> Option<&Package> {
self.packages.get(name)
}
2022-01-23 20:52:08 +00:00
}