Make "Store" a trait
This commit is contained in:
parent
d23e2f920d
commit
912c84e663
2 changed files with 8 additions and 42 deletions
|
@ -5,4 +5,5 @@ pub mod content;
|
|||
pub mod entry;
|
||||
pub mod error;
|
||||
pub mod header;
|
||||
pub mod store;
|
||||
|
||||
|
|
|
@ -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<T> = RResult<T, StoreError>;
|
||||
|
||||
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<RWLock<HashMap<PathBuf, File>>>,
|
||||
}
|
||||
fn location(&self) -> &PathBuf;
|
||||
|
||||
impl Store {
|
||||
|
||||
pub fn create(entry: Entry) -> Result<()> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn read(path: PathBuf) -> Result<Arc<RWLock<Entry>>> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn update(entry: Arc<RWLock<Entry>>) -> 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<Arc<RwLock<Entry>>>;
|
||||
fn update(&self, entry: Arc<RwLock<Entry>>) -> Result<()>;
|
||||
fn delete(&self, path: PathBuf) -> Result<()>;
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue