libimagentryannotation: Replace read with typed read
This commit is contained in:
parent
13ff09d8c6
commit
163bf249ff
2 changed files with 10 additions and 16 deletions
|
@ -28,12 +28,11 @@ use libimagentrylink::internal::InternalLinker;
|
||||||
use libimagentryutil::isa::Is;
|
use libimagentryutil::isa::Is;
|
||||||
use libimagentryutil::isa::IsKindHeaderPathProvider;
|
use libimagentryutil::isa::IsKindHeaderPathProvider;
|
||||||
|
|
||||||
use toml_query::read::TomlValueReadExt;
|
use toml_query::read::TomlValueReadTypeExt;
|
||||||
use toml_query::insert::TomlValueInsertExt;
|
use toml_query::insert::TomlValueInsertExt;
|
||||||
|
|
||||||
use error::Result;
|
use error::Result;
|
||||||
use error::AnnotationErrorKind as AEK;
|
use error::AnnotationErrorKind as AEK;
|
||||||
use error::AnnotationError as AE;
|
|
||||||
use error::ResultExt;
|
use error::ResultExt;
|
||||||
|
|
||||||
use iter::*;
|
use iter::*;
|
||||||
|
@ -75,12 +74,9 @@ impl Annotateable for Entry {
|
||||||
fn denotate<'a>(&mut self, store: &'a Store, ann_name: &str) -> Result<Option<FileLockEntry<'a>>> {
|
fn denotate<'a>(&mut self, store: &'a Store, ann_name: &str) -> Result<Option<FileLockEntry<'a>>> {
|
||||||
for annotation in self.annotations(store)? {
|
for annotation in self.annotations(store)? {
|
||||||
let mut anno = annotation?;
|
let mut anno = annotation?;
|
||||||
let name = match anno.get_header().read("annotation.name")? {
|
let name = match anno.get_header().read_string("annotation.name")? {
|
||||||
|
Some(ref name) => name.clone(),
|
||||||
None => continue,
|
None => continue,
|
||||||
Some(val) => match *val {
|
|
||||||
Value::String(ref name) => name.clone(),
|
|
||||||
_ => return Err(AE::from_kind(AEK::HeaderTypeError)),
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if name == ann_name {
|
if name == ann_name {
|
||||||
|
|
|
@ -17,8 +17,7 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
use toml::Value;
|
use toml_query::read::TomlValueReadTypeExt;
|
||||||
use toml_query::read::TomlValueReadExt;
|
|
||||||
|
|
||||||
use libimagstore::store::Store;
|
use libimagstore::store::Store;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
|
@ -26,7 +25,6 @@ use libimagstore::storeid::StoreIdIterator;
|
||||||
|
|
||||||
use error::Result;
|
use error::Result;
|
||||||
use error::AnnotationErrorKind as AEK;
|
use error::AnnotationErrorKind as AEK;
|
||||||
use error::AnnotationError as AE;
|
|
||||||
use error::ResultExt;
|
use error::ResultExt;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -47,11 +45,11 @@ impl<'a> Iterator for AnnotationIter<'a> {
|
||||||
loop {
|
loop {
|
||||||
match self.0.next().map(|id| self.1.get(id)) {
|
match self.0.next().map(|id| self.1.get(id)) {
|
||||||
Some(Ok(Some(entry))) => {
|
Some(Ok(Some(entry))) => {
|
||||||
match entry.get_header().read("annotation.is_annotation") {
|
match entry.get_header().read_bool("annotation.is_annotation").chain_err(|| AEK::HeaderReadError) {
|
||||||
Ok(None) => continue, // not an annotation
|
Ok(None) => continue, // not an annotation
|
||||||
Ok(Some(&Value::Boolean(true))) => return Some(Ok(entry)),
|
Ok(Some(false)) => continue,
|
||||||
Ok(Some(_)) => return Some(Err(AE::from_kind(AEK::HeaderTypeError))),
|
Ok(Some(true)) => return Some(Ok(entry)),
|
||||||
Err(e) => return Some(Err(e).chain_err(|| AEK::HeaderReadError)),
|
Err(e) => return Some(Err(e)),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Some(Ok(None)) => continue,
|
Some(Ok(None)) => continue,
|
||||||
|
|
Loading…
Reference in a new issue