56 lines
1.0 KiB
Rust
56 lines
1.0 KiB
Rust
use std::path::Path;
|
|
|
|
|
|
#[cfg(test)]
|
|
pub mod tests;
|
|
pub mod store;
|
|
pub mod song;
|
|
pub mod playlist;
|
|
pub mod query;
|
|
|
|
pub type Result<T> = anyhow::Result<T>;
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct Manifest<ST: store::BaseStore> {
|
|
store: Box<ST>,
|
|
}
|
|
|
|
impl<ST: store::BaseStore + Clone> Manifest<ST> {
|
|
pub fn new(p: &Path) -> Result<Self>{
|
|
let mut store = ST::empty();
|
|
if p.exists() {
|
|
store.load_from(p)?;
|
|
} else {
|
|
store.save_to(p)?;
|
|
}
|
|
store.save_original_path(p);
|
|
Ok(Self {
|
|
store: Box::new(store)
|
|
})
|
|
}
|
|
pub fn store(&self) -> &ST {
|
|
self.store.as_ref()
|
|
}
|
|
pub fn store_mut(&mut self) -> &mut ST {
|
|
self.store.as_mut()
|
|
}
|
|
pub fn save(&self) -> Result<()> {
|
|
self.store().save_to(self.store().get_original_path())?;
|
|
Ok(())
|
|
}
|
|
pub fn load(&mut self) -> Result<()> {
|
|
let p = self.store().get_original_path().to_path_buf();
|
|
self.store_mut().load_from(&p)?;
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|