summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Boeckel <mathstuf@gmail.com>2020-04-08 22:44:04 -0400
committerBen Boeckel <mathstuf@gmail.com>2020-04-09 10:32:09 -0400
commitcd1c566c8a68b097235e57267b8106ceee150e2a (patch)
tree01210dab6449e5999c4fffb8f70ebec481404c09
parent463bac13f984892f041a13184e1a651d00cf3af8 (diff)
error: remove the Result type alias
Instead, make a local type alias that can be used within the crate, but avoid the need to export yet another symbol.
-rw-r--r--src/component.rs6
-rw-r--r--src/error.rs2
-rw-r--r--src/icalendar.rs17
-rw-r--r--src/parser.rs22
-rw-r--r--src/vcard.rs4
5 files changed, 25 insertions, 26 deletions
diff --git a/src/component.rs b/src/component.rs
index f87e992..a11d38d 100644
--- a/src/component.rs
+++ b/src/component.rs
@@ -72,13 +72,13 @@ impl FromStr for Component {
type Err = VObjectErrorKind;
/// 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> {
+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);
@@ -89,7 +89,7 @@ pub fn parse_component(s: &str) -> Result<Component> {
}
/// 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 = parser.consume_component()?;
let new_s = if parser.eof() {
diff --git a/src/error.rs b/src/error.rs
index b9c7b3a..28f39e0 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -14,4 +14,4 @@ pub enum VObjectErrorKind {
ChronoError(::chrono::format::ParseError),
}
-pub type Result<T> = ::std::result::Result<T, VObjectErrorKind>;
+pub(crate) type VObjectResult<T> = Result<T, VObjectErrorKind>;
diff --git a/src/icalendar.rs b/src/icalendar.rs
index c49e193..4863029 100644
--- a/src/icalendar.rs
+++ b/src/icalendar.rs
@@ -1,4 +1,3 @@
-use std::result::Result as RResult;
use std::collections::BTreeMap;
use component::Component;
@@ -23,7 +22,7 @@ impl ICalendar {
/// Returns an error if the parsed text is not a ICalendar (that means that an error is
/// returned also if this is a valid Vcard!)
///
- pub fn build(s: &str) -> Result<ICalendar> {
+ pub fn build(s: &str) -> VObjectResult<ICalendar> {
let c = parse_component(s)?;
Self::from_component(c).map_err(|_| VObjectErrorKind::NotAnICalendar(s.to_owned()))
}
@@ -45,7 +44,7 @@ impl ICalendar {
}
/// Wrap a Component into a Vcard object, or don't do it if the Component is not a Vcard.
- pub fn from_component(c: Component)-> RResult<ICalendar, Component> {
+ pub fn from_component(c: Component)-> Result<ICalendar, Component> {
if c.name == "VCALENDAR" {
Ok(ICalendar(c))
} else {
@@ -99,7 +98,7 @@ impl<'a> EventIterator<'a> {
}
impl<'a> Iterator for EventIterator<'a> {
- type Item = RResult<Event<'a>, &'a Component>;
+ type Item = Result<Event<'a>, &'a Component>;
fn next(&mut self) -> Option<Self::Item> {
self.0.next().map(Event::from_component)
@@ -111,7 +110,7 @@ impl<'a> Iterator for EventIterator<'a> {
pub struct Event<'a>(&'a Component);
impl<'a> Event<'a> {
- fn from_component(c: &'a Component) -> RResult<Event<'a>, &'a Component> {
+ fn from_component(c: &'a Component) -> Result<Event<'a>, &'a Component> {
if c.name == "VEVENT" {
Ok(Event(c))
} else {
@@ -160,13 +159,13 @@ pub enum Time {
#[cfg(feature = "timeconversions")]
pub trait AsDateTime {
- fn as_datetime(&self) -> Result<Time>;
+ fn as_datetime(&self) -> VObjectResult<Time>;
}
#[cfg(feature = "timeconversions")]
impl AsDateTime for Dtend {
- fn as_datetime(&self) -> Result<Time> {
+ fn as_datetime(&self) -> VObjectResult<Time> {
match NaiveDateTime::parse_from_str(&self.0, DATE_TIME_FMT) {
Ok(dt) => Ok(Time::DateTime(dt)),
Err(_) => NaiveDate::parse_from_str(&self.0, DATE_FMT)
@@ -180,7 +179,7 @@ impl AsDateTime for Dtend {
#[cfg(feature = "timeconversions")]
impl AsDateTime for Dtstart {
- fn as_datetime(&self) -> Result<Time> {
+ fn as_datetime(&self) -> VObjectResult<Time> {
match NaiveDateTime::parse_from_str(&self.0, DATE_TIME_FMT) {
Ok(dt) => Ok(Time::DateTime(dt)),
Err(_) => NaiveDate::parse_from_str(&self.0, DATE_FMT)
@@ -194,7 +193,7 @@ impl AsDateTime for Dtstart {
#[cfg(feature = "timeconversions")]
impl AsDateTime for Dtstamp {
- fn as_datetime(&self) -> Result<Time> {
+ fn as_datetime(&self) -> VObjectResult<Time> {
match NaiveDateTime::parse_from_str(&self.0, DATE_TIME_FMT) {
Ok(dt) => Ok(Time::DateTime(dt)),
Err(_) => NaiveDate::parse_from_str(&self.0, DATE_FMT)
diff --git a/src/parser.rs b/src/parser.rs
index d46058a..0828b3e 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -55,7 +55,7 @@ impl<'s> Parser<'s> {
self.pos >= self.input.len()
}
- fn assert_char(&self, c: char) -> Result<()> {
+ fn assert_char(&self, c: char) -> VObjectResult<()> {
let real_c = match self.peek() {
Some((x, _)) => x,
None => {
@@ -86,7 +86,7 @@ impl<'s> Parser<'s> {
}
}
- fn consume_eol(&mut self) -> Result<()> {
+ fn consume_eol(&mut self) -> VObjectResult<()> {
let start_pos = self.pos;
let consumed = match self.consume_char() {
@@ -106,7 +106,7 @@ impl<'s> Parser<'s> {
}
}
- fn sloppy_terminate_line(&mut self) -> Result<()> {
+ fn sloppy_terminate_line(&mut self) -> VObjectResult<()> {
if !self.eof() {
self.consume_eol()?;
while let Ok(_) = self.consume_eol() {}
@@ -150,7 +150,7 @@ impl<'s> Parser<'s> {
res
}
- pub fn consume_property(&mut self) -> Result<Property> {
+ pub fn consume_property(&mut self) -> VObjectResult<Property> {
let group = self.consume_property_group().ok();
let name = self.consume_property_name()?;
let params = self.consume_params();
@@ -168,7 +168,7 @@ impl<'s> Parser<'s> {
})
}
- fn consume_property_name(&mut self) -> Result<String> {
+ fn consume_property_name(&mut self) -> VObjectResult<String> {
let rv = self.consume_while(|x| x == '-' || x.is_alphanumeric());
if rv.is_empty() {
Err(VObjectErrorKind::ParserError("No property name found.".to_owned()))
@@ -177,7 +177,7 @@ impl<'s> Parser<'s> {
}
}
- fn consume_property_group(&mut self) -> Result<String> {
+ fn consume_property_group(&mut self) -> VObjectResult<String> {
let start_pos = self.pos;
let name = self.consume_property_name();
@@ -196,18 +196,18 @@ impl<'s> Parser<'s> {
e
}
- fn consume_property_value(&mut self) -> Result<String> {
+ fn consume_property_value(&mut self) -> VObjectResult<String> {
let rv = self.consume_while(|x| x != '\r' && x != '\n');
self.sloppy_terminate_line()?;
Ok(rv)
}
- fn consume_param_name(&mut self) -> Result<String> {
+ fn consume_param_name(&mut self) -> VObjectResult<String> {
self.consume_property_name()
.map_err(|e| VObjectErrorKind::ParserError(format!("No param name found: {}", e)))
}
- fn consume_param_value(&mut self) -> Result<String> {
+ fn consume_param_value(&mut self) -> VObjectResult<String> {
let qsafe = |x| {
x != '"' &&
x != '\r' &&
@@ -226,7 +226,7 @@ impl<'s> Parser<'s> {
}
}
- fn consume_param(&mut self) -> Result<(String, String)> {
+ fn consume_param(&mut self) -> VObjectResult<(String, String)> {
let name = self.consume_param_name()?;
let start_pos = self.pos;
let value = if self.consume_only_char('=') {
@@ -252,7 +252,7 @@ impl<'s> Parser<'s> {
rv
}
- pub fn consume_component(&mut self) -> Result<Component> {
+ pub fn consume_component(&mut self) -> VObjectResult<Component> {
let start_pos = self.pos;
let mut property = self.consume_property()?;
if property.name != "BEGIN" {
diff --git a/src/vcard.rs b/src/vcard.rs
index 5a4d980..1729ede 100644
--- a/src/vcard.rs
+++ b/src/vcard.rs
@@ -22,7 +22,7 @@ impl Vcard {
/// Returns an error if the parsed text is not a Vcard (that means that an error is returned
/// also if this is a valid icalendar!)
///
- pub fn build(s: &str) -> Result<Vcard> {
+ pub fn build(s: &str) -> VObjectResult<Vcard> {
parse_component(s)
.and_then(|c| {
Self::from_component(c).map_err(|_| VObjectErrorKind::NotAVCard)
@@ -154,7 +154,7 @@ impl VcardBuilder {
}
}
- pub fn build(self) -> Result<Vcard> {
+ pub fn build(self) -> VObjectResult<Vcard> {
let mut v = Vcard::default();
v.set_properties(self.properties);
Ok(v)