Add Contact::is_contact()

This commit is contained in:
Matthias Beyer 2017-09-23 20:25:10 +02:00
parent f2bd241a59
commit 12e8657eb9

View file

@ -18,10 +18,14 @@
// //
use vobject::Component; use vobject::Component;
use toml::Value;
use toml_query::read::TomlValueReadExt;
use libimagstore::store::Entry; use libimagstore::store::Entry;
use libimagentryref::reference::Ref; use libimagentryref::reference::Ref;
use error::ContactError as CE;
use error::ContactErrorKind as CEK;
use error::Result; use error::Result;
use util; use util;
@ -30,6 +34,8 @@ use util;
/// Based on the functionality from libimagentryref, for fetching the Ical data from disk /// Based on the functionality from libimagentryref, for fetching the Ical data from disk
pub trait Contact : Ref { pub trait Contact : Ref {
fn is_contact(&self) -> Result<bool>;
// getting data // getting data
fn get_contact_data(&self) -> Result<ContactData>; fn get_contact_data(&self) -> Result<ContactData>;
@ -40,6 +46,15 @@ pub trait Contact : Ref {
impl Contact for Entry { impl Contact for Entry {
fn is_contact(&self) -> Result<bool> {
let location = "contact.marker";
match self.get_header().read(location)? {
Some(&Value::Boolean(b)) => Ok(b),
Some(_) => Err(CE::from_kind(CEK::HeaderTypeError("boolean", location))),
None => Ok(false)
}
}
fn get_contact_data(&self) -> Result<ContactData> { fn get_contact_data(&self) -> Result<ContactData> {
let component = self let component = self
.fs_file() .fs_file()