From 20a3b4e71b3706e1ee15a8f3d3d9640fd3a8b460 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Tue, 18 Dec 2018 13:05:32 +0100 Subject: Move reading of calendar file to function. --- src/main.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 43cdc5b..af10ccb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -55,11 +55,15 @@ fn print_event(event: &ical::parser::ical::component::IcalEvent) { summary); } -fn main() { - let buf = BufReader::new(File::open("test.ics").unwrap()); - let calendars: Vec<_> = ical::IcalParser::new(buf) +fn read_icalendar_from_file(filename: &str) -> std::io::Result> { + let buf = BufReader::new(File::open(filename)?); + Ok(ical::IcalParser::new(buf) .filter_map(|c| c.ok()) - .collect(); + .collect()) +} + +fn main() { + let calendars = read_icalendar_from_file("test.ics").unwrap(); println!("Found {} calendard in file...", calendars.len()); for c in calendars { -- cgit v1.2.3