rust-postgres/postgres-derive/src/enums.rs

29 lines
677 B
Rust
Raw Normal View History

2019-10-10 22:23:53 +00:00
use syn::{Error, Fields, Ident};
2019-10-10 02:23:12 +00:00
2019-10-10 22:23:53 +00:00
use crate::overrides::Overrides;
2019-10-10 02:23:12 +00:00
pub struct Variant {
pub ident: Ident,
pub name: String,
}
impl Variant {
pub fn parse(raw: &syn::Variant) -> Result<Variant, Error> {
match raw.fields {
Fields::Unit => {}
_ => {
return Err(Error::new_spanned(
raw,
"non-C-like enums are not supported",
))
}
}
let overrides = Overrides::extract(&raw.attrs)?;
Ok(Variant {
ident: raw.ident.clone(),
name: overrides.name.unwrap_or_else(|| raw.ident.to_string()),
})
}
}