Fix libimagnotes::{error, note}::* for new StoreId interface
This commit is contained in:
parent
c9612437fd
commit
63aa16de4e
2 changed files with 19 additions and 16 deletions
|
@ -9,4 +9,5 @@ generate_error_module!(
|
||||||
|
|
||||||
pub use self::error::NoteError;
|
pub use self::error::NoteError;
|
||||||
pub use self::error::NoteErrorKind;
|
pub use self::error::NoteErrorKind;
|
||||||
|
pub use self::error::MapErrInto;
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ use module_path::ModuleEntryPath;
|
||||||
use result::Result;
|
use result::Result;
|
||||||
use error::NoteError as NE;
|
use error::NoteError as NE;
|
||||||
use error::NoteErrorKind as NEK;
|
use error::NoteErrorKind as NEK;
|
||||||
|
use error::MapErrInto;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Note<'a> {
|
pub struct Note<'a> {
|
||||||
|
@ -32,11 +33,10 @@ impl<'a> Note<'a> {
|
||||||
|
|
||||||
debug!("Creating new Note: '{}'", name);
|
debug!("Creating new Note: '{}'", name);
|
||||||
let fle = {
|
let fle = {
|
||||||
let lockentry = store.create(ModuleEntryPath::new(name.clone()).into_storeid());
|
let mut lockentry = try!(ModuleEntryPath::new(name.clone())
|
||||||
if lockentry.is_err() {
|
.into_storeid()
|
||||||
return Err(NE::new(NEK::StoreWriteError, Some(Box::new(lockentry.unwrap_err()))));
|
.and_then(|id| store.create(id))
|
||||||
}
|
.map_err_into(NEK::StoreWriteError));
|
||||||
let mut lockentry = lockentry.unwrap();
|
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut entry = lockentry.deref_mut();
|
let mut entry = lockentry.deref_mut();
|
||||||
|
@ -93,24 +93,26 @@ impl<'a> Note<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete(store: &Store, name: String) -> Result<()> {
|
pub fn delete(store: &Store, name: String) -> Result<()> {
|
||||||
store.delete(ModuleEntryPath::new(name).into_storeid())
|
ModuleEntryPath::new(name)
|
||||||
.map_err(|e| NE::new(NEK::StoreWriteError, Some(Box::new(e))))
|
.into_storeid()
|
||||||
|
.and_then(|id| store.delete(id))
|
||||||
|
.map_err_into(NEK::StoreWriteError)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn retrieve(store: &Store, name: String) -> Result<Note> {
|
pub fn retrieve(store: &Store, name: String) -> Result<Note> {
|
||||||
store.retrieve(ModuleEntryPath::new(name).into_storeid())
|
ModuleEntryPath::new(name)
|
||||||
.map_err(|e| NE::new(NEK::StoreWriteError, Some(Box::new(e))))
|
.into_storeid()
|
||||||
|
.and_then(|id| store.retrieve(id))
|
||||||
|
.map_err_into(NEK::StoreWriteError)
|
||||||
.map(|entry| Note { entry: entry })
|
.map(|entry| Note { entry: entry })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(store: &Store, name: String) -> Result<Option<Note>> {
|
pub fn get(store: &Store, name: String) -> Result<Option<Note>> {
|
||||||
use libimagerror::into::IntoError;
|
ModuleEntryPath::new(name)
|
||||||
|
.into_storeid()
|
||||||
match store.get(ModuleEntryPath::new(name).into_storeid()) {
|
.and_then(|id| store.get(id))
|
||||||
Ok(Some(entry)) => Ok(Some(Note { entry: entry })),
|
.map_err_into(NEK::StoreWriteError)
|
||||||
Ok(None) => Ok(None),
|
.map(|o| o.map(|entry| Note { entry: entry }))
|
||||||
Err(e) => Err(NEK::StoreWriteError.into_error_with_cause(Box::new(e))),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn all_notes(store: &Store) -> Result<NoteIterator> {
|
pub fn all_notes(store: &Store) -> Result<NoteIterator> {
|
||||||
|
|
Loading…
Reference in a new issue