1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
use std::fs::File;
use std::io::prelude::*;
use std::path::Path;
mod task;
mod parse;
use parse::*;
mod html_calendar;
use html_calendar::*;
// https://doc.rust-lang.org/std/fs/struct.File.html
fn main() {
let path = Path::new("wtd.md");
let display = path.display();
// Open the path in read-only mode, returns `io::Result<File>`
let mut file = match File::open(&path) {
Err(why) => panic!("Error opening {}: {}", display, why),
Ok(file) => file,
};
// Read the file contents into a string, returns `io::Result<usize>`
let mut s = String::new();
match file.read_to_string(&mut s) {
Err(why) => panic!("Couldn't read {}: {}", display, why),
Ok(_) => {
let tasks = parse_file_str(&s);
let public_html = tasks_to_html(&tasks, CalendarPrivacy::Public);
let private_html = tasks_to_html(&tasks, CalendarPrivacy::Private);
// https://riptutorial.com/rust/example/4276/write-in-a-file
let mut public = File::create(Path::new("public.html")).unwrap();
writeln!(&mut public, "{}", public_html).unwrap();
let mut private = File::create(Path::new("private.html")).unwrap();
writeln!(&mut private, "{}", private_html).unwrap();
}
}
}
|