completed 05 ticket v2, started 06 tms
Some checks failed
CI / build (push) Failing after 1m54s
CI / gravity (push) Has been skipped
CI / is_fresh (push) Successful in 31s
CI / formatter (push) Failing after 7m2s

This commit is contained in:
2025-03-17 12:14:28 +05:30
parent 8413518a84
commit 2fa61e7715
9 changed files with 126 additions and 3 deletions

View File

@@ -4,3 +4,4 @@ version = "0.1.0"
edition = "2021"
[dependencies]
thiserror="*"

View File

@@ -8,6 +8,36 @@ enum Status {
Done,
}
// use thiserror::Error;
#[derive(Debug, thiserror::Error)]
#[error("{reason}, parsing failed.")]
struct ParseError {
reason: String,
}
impl TryFrom<String> for Status {
type Error = ParseError;
fn try_from(value: String) -> Result<Self, Self::Error> {
match value.to_lowercase().as_str() {
"todo" => Ok(Status::ToDo),
"done" => Ok(Status::Done),
"inprogress" => Ok(Status::InProgress),
_ => Err(ParseError {
reason: "Not Valid".to_string(),
}),
}
// Ok(Status::Done)
}
}
impl TryFrom<&str> for Status {
type Error = ParseError;
fn try_from(value: &str) -> Result<Self, Self::Error> {
value.to_string().try_into()
}
}
#[cfg(test)]
mod tests {
use super::*;