cbindgen
cbindgen copied to clipboard
Casts are not supported in constants.
The following fails and gives the following warning:
bitflags! {
pub struct Thing: u8 {
const READY = 'A' as u8;
}
}
Gives: WARN: Skip dutara_types::READY - (Unsupported expression. Cast(ExprCast { attrs: [], expr: Lit(ExprLit { attrs: [], lit: Char(LitChar { token: 'A' }) }), as_token: As, ty: Path(TypePath { qself: None, path: Path { leading_colon: None, segments: [PathSegment { ident: Ident(u8), arguments: None }] } }) }))
Replacing 'A' as u8
with 65
works fine.
I think it would be really neat if this was supported :)
You can probably use byte literals instead, so const READY = b'A'
, which is the right thing to do anyway. Supporting casts may be doable though. I don't plan to work on it right away, but it should be relatively straight-forward. See src/bindgen/ir/constant.rs
.
This is a problem for all constants, the following won't generate C
:
pub const A: u8 = 65;
pub const B: u8 = b'A';
pub const C: u8 = 'A' as u8;