Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[derive(Debug, Hash, Copy, Clone)]
- enum Action {
- Begin(NaiveDateTime, usize),
- Asleep(NaiveDateTime),
- Wake(NaiveDateTime),
- }
- impl FromStr for Action {
- type Err = ();
- fn from_str(s: &str) -> Result<Self, Self::Err> {
- let (date, action) = s.split_at(18);
- let date = NaiveDateTime::parse_from_str(date, "[%Y-%m-%d %H:%M]").unwrap();
- Ok(match &action[1..] {
- "falls asleep" => Action::Asleep(date),
- "wakes up" => Action::Wake(date),
- _ => {
- let guard_id = action.split_whitespace().nth(1).unwrap()[1..]
- .parse()
- .unwrap();
- Action::Begin(date, guard_id)
- }
- })
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment