diff options
author | Teddy Wing | 2018-04-15 00:15:02 +0200 |
---|---|---|
committer | Teddy Wing | 2018-04-15 00:15:02 +0200 |
commit | 3a88d7caf02bdb7da3753423d938cbd226879f0c (patch) | |
tree | c1b15773259aee9bcb778d1597a710d1149df57d /src | |
parent | a937e1a2d79a64d525eae4cebb8a39cba123f3ac (diff) | |
download | meetup-find-events-rss-3a88d7caf02bdb7da3753423d938cbd226879f0c.tar.bz2 |
Add 'error-chain' to the main library
Use 'error-chain' here too. Seems like this will be a pretty useful
library.
Change the include in the 'meetup' `lib.rs` to allow us to export
`meetup::Error` instead of `meetup::errors::Error` to be consistent with
the error types of the other third-party libraries we're using.
Diffstat (limited to 'src')
-rw-r--r-- | src/build_rss.rs | 4 | ||||
-rw-r--r-- | src/errors.rs | 6 | ||||
-rw-r--r-- | src/lib.rs | 3 | ||||
-rw-r--r-- | src/meetup_rss.rs | 7 |
4 files changed, 15 insertions, 5 deletions
diff --git a/src/build_rss.rs b/src/build_rss.rs index 93430a1..0c31a43 100644 --- a/src/build_rss.rs +++ b/src/build_rss.rs @@ -1,4 +1,4 @@ -use std::error::Error; +use errors::*; use meetup::client; use meetup_rss; @@ -12,7 +12,7 @@ pub fn write_feed( end_date_range: String, radius: Option<String>, page: Option<String>, -) -> Result<(), Box<Error>> { +) -> Result<()> { let client = client::Client::new(token); let events = client.find_upcoming_events( latitude, diff --git a/src/errors.rs b/src/errors.rs new file mode 100644 index 0000000..d9e431b --- /dev/null +++ b/src/errors.rs @@ -0,0 +1,6 @@ +error_chain! { + foreign_links { + Meetup(::meetup::Error); + Rss(::rss::Error); + } +} @@ -1,7 +1,10 @@ +#[macro_use] +extern crate error_chain; extern crate rss; extern crate meetup; pub mod build_rss; +mod errors; mod meetup_rss; diff --git a/src/meetup_rss.rs b/src/meetup_rss.rs index 7dd2b9e..d1d3f5f 100644 --- a/src/meetup_rss.rs +++ b/src/meetup_rss.rs @@ -1,10 +1,11 @@ -use rss::{self, Channel, ChannelBuilder, Item}; +use rss::{Channel, ChannelBuilder, Item}; use std::io; +use errors::*; use meetup::event::Event; -pub fn generate(events: &Vec<Event>) -> Result<Channel, String> { +pub fn generate(events: &Vec<Event>) -> Result<Channel> { let items: Vec<Item> = events.into_iter().map(|event| { let mut item = Item::default(); item.set_title(event.name.clone()); @@ -24,7 +25,7 @@ pub fn generate(events: &Vec<Event>) -> Result<Channel, String> { } /// Writes the channel to standard output. -pub fn write(channel: Channel) -> Result<(), rss::Error> { +pub fn write(channel: Channel) -> Result<()> { let stdout = io::stdout(); let handle = stdout.lock(); |