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 entry;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod header;
|
pub mod header;
|
||||||
|
pub mod store;
|
||||||
|
|
||||||
|
|
|
@ -4,56 +4,21 @@ use std::ops::Drop;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::result::Result as RResult;
|
use std::result::Result as RResult;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::RWLock;
|
use std::sync::RwLock;
|
||||||
|
|
||||||
pub use entry::Entry;
|
pub use entry::Entry;
|
||||||
pub use error::StoreError;
|
pub use error::StoreError;
|
||||||
|
|
||||||
pub type Result<T> = RResult<T, StoreError>;
|
pub type Result<T> = RResult<T, StoreError>;
|
||||||
|
|
||||||
pub struct Store {
|
pub trait Store {
|
||||||
location: PathBuf,
|
|
||||||
|
|
||||||
/**
|
fn location(&self) -> &PathBuf;
|
||||||
* 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>>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Store {
|
fn create(&self, entry: Entry) -> Result<()>;
|
||||||
|
fn read(&self, path: PathBuf) -> Result<Arc<RwLock<Entry>>>;
|
||||||
pub fn create(entry: Entry) -> Result<()> {
|
fn update(&self, entry: Arc<RwLock<Entry>>) -> Result<()>;
|
||||||
unimplemented!()
|
fn delete(&self, path: PathBuf) -> Result<()>;
|
||||||
}
|
|
||||||
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue