use package system

main
NotAFile 2022-01-23 22:51:39 +01:00
parent a1f953e989
commit b22c348d8f
2 changed files with 19 additions and 4 deletions

View File

@ -26,7 +26,10 @@ struct Opt {
fn main() {
let opt = Opt::from_args();
let mut infile = File::open(opt.input).expect("could not open file");
// let mut infile = File::open(opt.input).expect("could not open file");
let packages = package::PackageRegistry::new();
let mut infile = packages.get("builtins").expect("no package").open().expect("could not open file");
let mut input = String::new();
infile
.read_to_string(&mut input)

View File

@ -1,17 +1,25 @@
use std::collections::BTreeMap;
use std::path::PathBuf;
use std::fs::File;
struct Package {
pub struct Package {
name: String,
path: PathBuf,
}
struct PackageRegistry {
impl Package {
pub fn open(&self) -> Result<File, std::io::Error> {
let filepath = self.path.with_file_name("main.hyd");
File::open(filepath)
}
}
pub struct PackageRegistry {
packages: BTreeMap<String, Package>
}
impl PackageRegistry {
fn new() -> Self {
pub fn new() -> Self {
let mut packages = BTreeMap::new();
packages.insert("builtins".to_string(), Package {
name: "builtins".to_string(),
@ -19,4 +27,8 @@ impl PackageRegistry {
});
Self { packages }
}
pub fn get(&self, name: &str) -> Option<&Package> {
self.packages.get(name)
}
}