diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-04-09 17:27:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-09 17:27:54 +0200 |
commit | 2ccf9bceaafdc24b1eca88288f5045cb69dd1b08 (patch) | |
tree | 9ae6ded3369ccdee0878b86a5319ecaeb66aaae7 /src/component.rs | |
parent | ea9780d1159afda4e4aaf3f7d7ea317b1fd420b7 (diff) | |
parent | d0d8bde43fe1355a740c0f431f7b10f4a2715823 (diff) |
Error cleanup
Diffstat (limited to 'src/component.rs')
-rw-r--r-- | src/component.rs | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/component.rs b/src/component.rs index 8330d18..f6d9ac0 100644 --- a/src/component.rs +++ b/src/component.rs @@ -2,7 +2,7 @@ use std::str::FromStr; use std::collections::BTreeMap; use property::Property; -use parser::Parser; +use parser::{Parser, ParseErrorReason}; use error::*; @@ -69,29 +69,28 @@ impl Component { } impl FromStr for Component { - type Err = VObjectErrorKind; + type Err = VObjectError; /// Same as `vobject::parse_component` - fn from_str(s: &str) -> Result<Component> { + fn from_str(s: &str) -> VObjectResult<Component> { parse_component(s) } } /// Parse exactly one component. Trailing data generates errors. -pub fn parse_component(s: &str) -> Result<Component> { - let (rv, new_s) = try!(read_component(s)); +pub fn parse_component(s: &str) -> VObjectResult<Component> { + let (rv, new_s) = read_component(s)?; if !new_s.is_empty() { - let s = format!("Trailing data: `{}`", new_s); - return Err(VObjectErrorKind::ParserError(s)); + return Err(ParseErrorReason::TrailingData(new_s.into()).into()); } Ok(rv) } /// Parse one component and return the rest of the string. -pub fn read_component(s: &str) -> Result<(Component, &str)> { +pub fn read_component(s: &str) -> VObjectResult<(Component, &str)> { let mut parser = Parser::new(s); - let rv = try!(parser.consume_component()); + let rv = parser.consume_component()?; let new_s = if parser.eof() { "" } else { |