mirror of
https://github.com/Sarsoo/csbindgen.git
synced 2024-12-23 06:56:27 +00:00
Merge pull request #52 from xanathar/pr/enum-negative-values
Added support for enums with negative values
This commit is contained in:
commit
3df9df4e41
@ -314,11 +314,20 @@ pub fn collect_enum(ast: &syn::File, result: &mut Vec<RustEnum>) {
|
|||||||
for v in &t.variants {
|
for v in &t.variants {
|
||||||
let name = v.ident.to_string();
|
let name = v.ident.to_string();
|
||||||
let mut value = None;
|
let mut value = None;
|
||||||
if let Some((_, syn::Expr::Lit(x))) = &v.discriminant {
|
|
||||||
if let syn::Lit::Int(x) = &x.lit {
|
match &v.discriminant {
|
||||||
|
Some((_, syn::Expr::Lit(x))) => if let syn::Lit::Int(x) = &x.lit {
|
||||||
let digits = x.base10_digits().to_string();
|
let digits = x.base10_digits().to_string();
|
||||||
value = Some(digits);
|
value = Some(digits);
|
||||||
}
|
}
|
||||||
|
Some((_, syn::Expr::Unary(u))) if matches!(u.op, syn::UnOp::Neg(_)) => {
|
||||||
|
if let syn::Expr::Lit(x) = &*u.expr {
|
||||||
|
if let syn::Lit::Int(x) = &x.lit {
|
||||||
|
value = Some(format!("-{}", x.base10_digits()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
fields.push((name, value));
|
fields.push((name, value));
|
||||||
|
Loading…
Reference in New Issue
Block a user