2024-11-06 10:12:07 +00:00
|
|
|
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>;
|
|
|
|
|
|
|
|
pub struct Manifest<ST: store::BaseStore> {
|
|
|
|
store: Box<ST>,
|
2024-10-22 18:54:32 +00:00
|
|
|
}
|
2024-11-06 10:12:07 +00:00
|
|
|
|
|
|
|
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(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|