summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2017-11-19 15:11:30 +0100
committerMatthias Beyer <mail@beyermatthias.de>2017-11-19 15:15:12 +0100
commit005cc132a23534d7c690f4606c26303ab79da511 (patch)
treeb3232c9802331dd6f3bc60933eaffe526724624a
parent633e1a707da7bc93191c7dfd8090a5ed91a19607 (diff)
Make example output pretty
-rw-r--r--examples/main.rs42
1 files changed, 24 insertions, 18 deletions
diff --git a/examples/main.rs b/examples/main.rs
index 3c301cf..75bc9ff 100644
--- a/examples/main.rs
+++ b/examples/main.rs
@@ -1,31 +1,37 @@
extern crate kairos;
+use kairos::timetype::TimeType as TT;
+
+fn pretty_print(tt: TT) {
+ match tt {
+ TT::Seconds(e) => println!("{} Seconds", e),
+ TT::Minutes(e) => println!("{} Minutes", e),
+ TT::Hours(e) => println!("{} Hours", e),
+ TT::Days(e) => println!("{} Days", e),
+ TT::Months(e) => println!("{} Months", e),
+ TT::Years(e) => println!("{} Years", e),
+ TT::Moment(ndt) => println!("{} ", ndt),
+ other => println!("Cannot pretty-print: '{:?}'", other),
+ }
+}
+
fn main() {
// not sure whether this is actually fast or something, but we don't care here, do we?
let s = ::std::env::args().skip(1).fold(String::new(), |acc, obj| format!("{} {}", acc, obj));
let s = s.trim(); // because kairos is not yet whitespace tolerant
- println!("Parsing: '{}'", s);
match kairos::parser::parse(s) {
Err(e) => println!("Error -> {:?}", e),
- Ok(kairos::parser::Parsed::TimeType(tt)) => {
- println!("Having TimeType");
-
- match tt.calculate() {
- Ok(r) => println!("{:?}", r),
- Err(e) => println!("Error calculating: {:?}", e),
- }
+ Ok(kairos::parser::Parsed::TimeType(tt)) => match tt.calculate() {
+ Ok(r) => pretty_print(r),
+ Err(e) => println!("Error calculating: {:?}", e),
},
- Ok(kairos::parser::Parsed::Iterator(Ok(ui))) => {
- println!("Having iterator");
-
- for elem in ui {
- match elem {
- Ok(r) => println!("{:?}", r),
- Err(e) => {
- println!("Error calculating: {:?}", e);
- ::std::process::exit(1)
- }
+ Ok(kairos::parser::Parsed::Iterator(Ok(ui))) => for elem in ui {
+ match elem {
+ Ok(r) => pretty_print(r),
+ Err(e) => {
+ println!("Error calculating: {:?}", e);
+ ::std::process::exit(1)
}
}
},