diff options
author | Markus Unterwaditzer <markus@unterwaditzer.net> | 2015-01-22 16:09:01 +0100 |
---|---|---|
committer | Markus Unterwaditzer <markus@unterwaditzer.net> | 2015-01-22 16:09:01 +0100 |
commit | 888a7f6ea6a70d511f93df6ca81c881d0343a224 (patch) | |
tree | bdc67065dfc8291b0d710a59d7fe53372a733148 /src/vobject | |
parent | 3336144e8de4455e10f1fab15f5a60c777386502 (diff) |
implement FromStr
Diffstat (limited to 'src/vobject')
-rw-r--r-- | src/vobject/lib.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/vobject/lib.rs b/src/vobject/lib.rs index 5c253e2..1f8319e 100644 --- a/src/vobject/lib.rs +++ b/src/vobject/lib.rs @@ -6,7 +6,7 @@ use std::collections::HashMap; use std::collections::hash_map::Entry::{Occupied, Vacant}; - +use std::str::FromStr; pub struct Property { @@ -90,6 +90,16 @@ impl Component { } } +impl FromStr for Component { + /// Same as `vobject::parse_component`, but without the error messages. + fn from_str(s: &str) -> Option<Component> { + match parse_component(s) { + Ok(x) => Some(x), + Err(_) => None + } + } +} + /// Parse a component. The error value is a human-readable message. pub fn parse_component(s: &str) -> Result<Component, String> { // XXX: The unfolding should be worked into the PEG |