Skip to content

Instantly share code, notes, and snippets.

@bitdivine
Last active October 11, 2024 12:36
Show Gist options
  • Save bitdivine/1e2195050d003c302c27a8b47bd08eaf to your computer and use it in GitHub Desktop.
Save bitdivine/1e2195050d003c302c27a8b47bd08eaf to your computer and use it in GitHub Desktop.
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