feat: resources

This commit is contained in:
Nova
2022-08-19 12:17:54 -04:00
parent 6de5d9b7ac
commit 11299716d9
2 changed files with 38 additions and 0 deletions

View File

@@ -1,3 +1,4 @@
pub mod resource;
pub mod client;
pub mod eventloop;
pub mod nodelist;

37
src/core/resource.rs Normal file
View File

@@ -0,0 +1,37 @@
use std::path::PathBuf;
pub type ResourceID = Box<dyn ResourceIDTrait + Send + Sync>;
pub trait ResourceIDTrait {
fn get_file(&self, prefixes: &Vec<PathBuf>) -> Option<PathBuf>;
}
impl ResourceIDTrait for PathBuf {
fn get_file(&self, _prefixes: &Vec<PathBuf>) -> Option<PathBuf> {
if self.is_absolute() && self.as_path().exists() {
Some(self.clone())
} else {
None
}
}
}
pub struct NamespacedResourceID {
pub namespace: String,
pub path: PathBuf,
}
impl ResourceIDTrait for NamespacedResourceID {
fn get_file(&self, prefixes: &Vec<PathBuf>) -> Option<PathBuf> {
for prefix in prefixes {
let mut path = prefix.clone();
path.push(self.namespace.clone());
path.push(self.path.clone());
if path.as_path().exists() {
return Some(path);
}
}
None
}
}