Add documentation to src/store.rs

This commit is contained in:
Marcel Müller 2016-01-16 20:53:38 +01:00
parent 313a0f9d7e
commit cfc6e860b1
No known key found for this signature in database
GPG key ID: DD4ED37D0CAC76E2

View file

@ -11,10 +11,14 @@ use fs2::FileExt;
use entry::Entry; use entry::Entry;
use error::StoreError; use error::StoreError;
/// The Result Type returned by any interaction with the store that could fail
pub type Result<T> = RResult<T, StoreError>; pub type Result<T> = RResult<T, StoreError>;
/// The Index into the Store
pub type StoreId = PathBuf; pub type StoreId = PathBuf;
/// This Trait allows you to convert various representations to a single one
/// suitable for usage in the Store
trait IntoStoreId { trait IntoStoreId {
fn into_storeid(self) -> StoreId; fn into_storeid(self) -> StoreId;
} }
@ -58,26 +62,35 @@ impl<ISI: IntoStoreId> IntoStoreId for (ISI, ISI) {
} }
} }
/// A store entry, depending on the option type it is either borrowed currently
/// or not.
struct StoreEntry { struct StoreEntry {
file: File, file: File,
entry: Option<Entry>, entry: Option<Entry>,
} }
impl StoreEntry { impl StoreEntry {
/// The entry is currently borrowed, meaning that some thread is currently
/// mutating it
fn is_borrowed(&self) -> bool { fn is_borrowed(&self) -> bool {
self.entry.is_none() self.entry.is_none()
} }
/// Set the entry to the given one. This will also overwrite the entry
/// and flush it to disk
fn set_entry(&mut self, entry: Entry) -> Result<()> { fn set_entry(&mut self, entry: Entry) -> Result<()> {
self.entry = Some(entry); self.entry = Some(entry);
unimplemented!() unimplemented!()
} }
/// We borrow the entry
fn get_entry(&mut self) -> Result<Entry> { fn get_entry(&mut self) -> Result<Entry> {
unimplemented!() unimplemented!()
} }
} }
/// The Store itself, through this object one can interact with IMAG's entries
pub struct Store { pub struct Store {
location: PathBuf, location: PathBuf,
@ -92,22 +105,29 @@ pub struct Store {
} }
impl Store { impl Store {
/// Creates the Entry at the given location (inside the entry)
pub fn create(&self, entry: Entry) -> Result<()> { pub fn create(&self, entry: Entry) -> Result<()> {
unimplemented!(); unimplemented!();
} }
/// Borrow a given Entry. When the `FileLockEntry` is either `update`d or
/// dropped, the new Entry is written to disk
pub fn retrieve<'a>(&'a self, id: StoreId) -> Result<FileLockEntry<'a>> { pub fn retrieve<'a>(&'a self, id: StoreId) -> Result<FileLockEntry<'a>> {
unimplemented!(); unimplemented!();
} }
/// Return the `FileLockEntry` and write to disk
pub fn update<'a>(&'a self, entry: FileLockEntry<'a>) -> Result<()> { pub fn update<'a>(&'a self, entry: FileLockEntry<'a>) -> Result<()> {
unimplemented!(); unimplemented!();
} }
/// Retrieve a copy of a given entry, this cannot be used to mutate
/// the one on disk
pub fn retrieve_copy(&self, id: StoreId) -> Result<Entry> { pub fn retrieve_copy(&self, id: StoreId) -> Result<Entry> {
unimplemented!(); unimplemented!();
} }
/// Delete an entry
pub fn delete(&self, id: StoreId) -> Result<()> { pub fn delete(&self, id: StoreId) -> Result<()> {
unimplemented!(); unimplemented!();
} }
@ -127,6 +147,7 @@ impl Drop for Store {
} }
/// A struct that allows you to borrow an Entry
pub struct FileLockEntry<'a> { pub struct FileLockEntry<'a> {
store: &'a Store, store: &'a Store,
entry: Entry, entry: Entry,