type from_string Result repetition #3478
Answered
by
giacomocavalieri
bobjoe12131
asked this question in
Questions & support
-
I am writing a simple from_string for a type with the days of the week: pub fn from_string(str: String) -> Result(DayOfWeek, Nil) {
case str {
"Monday" -> Ok(Monday)
"Tuesday" -> Ok(Tuesday)
"Wednesday" -> Ok(Wednesday)
"Thursday" -> Ok(Thursday)
"Friday" -> Ok(Friday)
"Saturday" -> Ok(Saturday)
"Sunday" -> Ok(Sunday)
_ -> Error(Nil)
}
} The thing i am wondering about is the line of OK(...) Is this The way or is there another way? Maybe i am just missing early returns. Edit: made fn my actual usecase. |
Beta Was this translation helpful? Give feedback.
Answered by
giacomocavalieri
Aug 2, 2024
Replies: 1 comment
-
Yeah this looks totally fine to me! |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
bobjoe12131
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah this looks totally fine to me!