Partially implement get_entry
This commit is contained in:
parent
50413101c4
commit
97b7090824
2 changed files with 21 additions and 22 deletions
|
@ -8,7 +8,7 @@ use toml;
|
||||||
/**
|
/**
|
||||||
* Kind of store error
|
* Kind of store error
|
||||||
*/
|
*/
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
pub enum StoreErrorKind {
|
pub enum StoreErrorKind {
|
||||||
FileError,
|
FileError,
|
||||||
IdLocked,
|
IdLocked,
|
||||||
|
|
|
@ -21,39 +21,38 @@ use lazyfile::LazyFile;
|
||||||
pub type Result<T> = RResult<T, StoreError>;
|
pub type Result<T> = RResult<T, StoreError>;
|
||||||
|
|
||||||
|
|
||||||
/// A store entry, depending on the option type it is either borrowed currently
|
#[derive(PartialEq)]
|
||||||
/// or not.
|
enum StoreEntryStatus {
|
||||||
enum StoreEntry {
|
Present,
|
||||||
Present(StoreId, LazyFile),
|
|
||||||
Borrowed
|
Borrowed
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq for StoreEntry {
|
/// A store entry, depending on the option type it is either borrowed currently
|
||||||
fn eq(&self, other: &StoreEntry) -> bool {
|
/// or not.
|
||||||
use store::StoreEntry::*;
|
struct StoreEntry {
|
||||||
match (*self, *other) {
|
id: StoreId,
|
||||||
(Borrowed, Borrowed) => true,
|
file: LazyFile,
|
||||||
(Borrowed, Present(_,_)) => false,
|
status: StoreEntryStatus,
|
||||||
(Present(_,_), Borrowed) => false,
|
|
||||||
(Present(ref a,_), Present(ref b, _)) => a == b
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl StoreEntry {
|
impl StoreEntry {
|
||||||
/// The entry is currently borrowed, meaning that some thread is currently
|
/// The entry is currently borrowed, meaning that some thread is currently
|
||||||
/// mutating it
|
/// mutating it
|
||||||
fn is_borrowed(&self) -> bool {
|
fn is_borrowed(&self) -> bool {
|
||||||
*self == StoreEntry::Borrowed
|
self.status == StoreEntryStatus::Borrowed
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_entry(&self) -> Result<Entry> {
|
fn get_entry(&mut self) -> Result<Entry> {
|
||||||
if let &StoreEntry::Present(ref id, ref file) = self {
|
if !self.is_borrowed() {
|
||||||
let file = file.get_file();
|
let file = self.file.get_file();
|
||||||
if let Err(StoreError{err_type: StoreErrorKind::FileNotFound, ..}) = file {
|
if let Err(err) = file {
|
||||||
Ok(Entry::new(id.clone()))
|
if err.err_type() == StoreErrorKind::FileNotFound {
|
||||||
|
Ok(Entry::new(self.id.clone()))
|
||||||
} else {
|
} else {
|
||||||
|
Err(err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// TODO:
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue