1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
extern crate chrono; use chrono::prelude::*; #[derive(Debug)] pub struct Learned { pub description: String, pub date: Date<Local>, } impl Learned { pub fn new(args: Vec<String>) -> Result<Learned, &'static str> { if args.len() < 2 { return Err("not enough arguments"); } let description = args.clone().split_off(1).join(" "); let date = Local::today(); Ok(Learned { description, date }) } }