I need to change the FXME code to iterate each identifier.
macro_rules! sql_string_enum {
( $enumname: ident {
$($enumvals: ident,)*
} ) => {
use std::result;
use std::str::FromStr;
#[derive(Debug)]
pub enum $enumname {
$($enumvals,)*
}
impl FromStr for $enumname {
type Err = &'static str;
fn from_str(s: &str) -> result::Result<Self, Self::Err> {
match s {
//FIXME: This is where I need to iterate identifiers instead of hardcoding
"ROLE" => Ok($enumname::ROLE),
"USER" => Ok($enumname::USER),
_ => Err("Not a valid resource value"),
}
}
}
}
}
fn main() {
sql_string_enum!( Resource { ROLE, USER, });
}