imag/libimagstore/src/store.rs

54 lines
1.2 KiB
Rust
Raw Normal View History

2016-01-13 20:47:23 +00:00
use std::collections::HashMap;
use std::fs::File;
2016-01-13 20:51:40 +00:00
use std::ops::Drop;
2016-01-12 17:52:03 +00:00
use std::path::PathBuf;
use std::result::Result as RResult;
use std::sync::Arc;
2016-01-13 21:03:53 +00:00
use std::sync::RwLock;
2016-01-12 17:52:03 +00:00
pub use entry::Entry;
pub use error::StoreError;
pub type Result<T> = RResult<T, StoreError>;
pub trait Store : Sized {
2016-01-13 20:47:23 +00:00
2016-01-13 21:03:53 +00:00
fn location(&self) -> &PathBuf;
2016-01-13 20:51:40 +00:00
2016-01-13 21:03:53 +00:00
fn create(&self, entry: Entry) -> Result<()>;
fn retrieve<'a>(&'a self, path: PathBuf) -> Result<FileLockEntry<'a, Self>>;
fn update<'a>(&'a self, entry: FileLockEntry<'a, Self>) -> Result<()>;
2016-01-16 14:11:20 +00:00
fn retrieve_copy(&self, id : String) -> Result<Entry>;
2016-01-13 21:03:53 +00:00
fn delete(&self, path: PathBuf) -> Result<()>;
2016-01-13 20:51:40 +00:00
}
2016-01-16 17:25:48 +00:00
pub struct FileLockEntry<'a, S: Store + 'a> {
store: &'a S,
entry: Entry
}
impl<'a, S: Store + 'a> FileLockEntry<'a, S > {
fn new(store: &'a S, entry: Entry) -> FileLockEntry<'a, S> {
FileLockEntry {
store: store,
entry: entry,
}
}
}
impl<'a, S: Store + 'a> ::std::ops::Deref for FileLockEntry<'a, S> {
type Target = Entry;
fn deref(&self) -> &Self::Target {
&self.entry
}
}
impl<'a, S: Store + 'a> ::std::ops::DerefMut for FileLockEntry<'a, S> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.entry
}
}