From 06bfe8e18a9d61fd4086e396eccb40570d3d3d48 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Sat, 10 Aug 2024 18:16:21 +0300 Subject: [PATCH] fix(task): properly parse str into State --- src/task.rs | 13 ++++++++++++- src/tasks.rs | 6 +----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/task.rs b/src/task.rs index ee17711..aa078cf 100644 --- a/src/task.rs +++ b/src/task.rs @@ -219,6 +219,17 @@ pub(crate) enum State { Pending, Procedure, } +impl From<&str> for State { + fn from(value: &str) -> Self { + match value { + "Closed" => State::Closed, + "Done" => State::Done, + "Pending" => State::Pending, + "Proc" | "Procedure" | "List" => State::Procedure, + _ => State::Open, + } + } +} impl TryFrom for State { type Error = (); @@ -236,7 +247,7 @@ impl TryFrom for State { impl State { pub(crate) fn is_open(&self) -> bool { match self { - State::Open | State::Procedure => true, + State::Open | State::Pending | State::Procedure => true, _ => false, } } diff --git a/src/tasks.rs b/src/tasks.rs index 003fd22..0f799bf 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -712,11 +712,7 @@ impl Tasks { } pub(crate) fn set_state_for_with(&mut self, id: EventId, comment: &str) { - self.set_state_for(id, comment, match comment { - "Closed" => State::Closed, - "Done" => State::Done, - _ => State::Open, - }); + self.set_state_for(id, comment, comment.into()); } pub(crate) fn set_state_for(&mut self, id: EventId, comment: &str, state: State) -> EventId {