completed 05 ticket v2, started 06 tms
This commit is contained in:
@@ -4,3 +4,4 @@ version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
thiserror="*"
|
||||
|
||||
@@ -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::*;
|
||||
|
||||
Reference in New Issue
Block a user