use std::path::{Path, PathBuf};
#[allow(missing_copy_implementations)]
pub struct Package {
pub data: &'static [(&'static [u8], &'static [u8])]
}
pub struct Iter<'a>(std::slice::Iter<'a, (&'static [u8], &'static [u8])>);
impl Package {
pub fn find<P>(&self, resource: P) -> Option<&'static [u8]> where P: AsRef<Path> {
let resource = resource.as_ref();
self.data.iter().find(|&&(path, _)| {
Path::new(&String::from_utf8(path.to_vec()).unwrap()) == resource
}).map(|v| v.1)
}
pub fn iter<'a>(&'a self) -> Iter<'a> {
Iter(self.data.iter())
}
}
impl<'a> Iterator for Iter<'a> {
type Item = (PathBuf, &'static [u8]);
fn next(&mut self) -> Option<(PathBuf, &'static [u8])> {
match self.0.next() {
None => None,
Some(&(path, content)) => {
Some((PathBuf::from(&String::from_utf8(path.to_vec()).unwrap()), content))
}
}
}
}