diff --git a/libimagstore/src/lib.rs b/libimagstore/src/lib.rs index fadd3bcf..12c0e09d 100644 --- a/libimagstore/src/lib.rs +++ b/libimagstore/src/lib.rs @@ -5,4 +5,5 @@ pub mod content; pub mod entry; pub mod error; pub mod header; +pub mod store; diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index 4f3af960..dc7baf1d 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -4,56 +4,21 @@ use std::ops::Drop; use std::path::PathBuf; use std::result::Result as RResult; use std::sync::Arc; -use std::sync::RWLock; +use std::sync::RwLock; pub use entry::Entry; pub use error::StoreError; pub type Result = RResult; -pub struct Store { - location: PathBuf, +pub trait Store { - /** - * Internal Path->File cache map - * - * Caches the files, so they remain flock()ed - * - * Could be optimized for a threadsafe HashMap - */ - cache: Arc>>, -} + fn location(&self) -> &PathBuf; -impl Store { - - pub fn create(entry: Entry) -> Result<()> { - unimplemented!() - } - - pub fn read(path: PathBuf) -> Result>> { - unimplemented!() - } - - pub fn update(entry: Arc>) -> Result<()> { - unimplemented!() - } - - pub fn delete(path: PathBuf) -> Result<()> { - unimplemented!() - } - -} - -impl Drop for Store { - - /** - * Unlock all files on drop - * - * TODO: Error message when file cannot be unlocked? - */ - fn drop(&mut self) { - self.cache.iter().map(|f| f.unlock()); - } + fn create(&self, entry: Entry) -> Result<()>; + fn read(&self, path: PathBuf) -> Result>>; + fn update(&self, entry: Arc>) -> Result<()>; + fn delete(&self, path: PathBuf) -> Result<()>; }