Last active
October 11, 2024 12:36
-
-
Save bitdivine/1e2195050d003c302c27a8b47bd08eaf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::str::FromStr; | |
#[derive(Debug, PartialEq, Eq, EnumString)] | |
enum ApiMethod { | |
GetState, | |
SetLocale, | |
} | |
impl TryFrom<&str> for ApiMethod { | |
.. | |
fn from(s: &str) -> Result<Self, Err> { | |
match { | |
'/state' => Ok(ApiMethod::GetState), | |
'/config/locale' => Ok(APiMethod::SetLocale), | |
_ => Err(..) | |
} | |
} | |
} | |
let method = ApiMethod::try_from("/config/locale").expect("Unknown method"); | |
match method { | |
ApiMethod::GetState => unimplemented!(), | |
ApiMethod::SetLocale => unimplemented!(), | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment