2 unstable releases
0.2.0 | Sep 24, 2023 |
---|---|
0.1.0 | Jun 24, 2023 |
#70 in #i32
82 downloads per month
Used in cxc
11KB
194 lines
🪞 cxc-derive: Make any type usable in cxc
use cxc::Unit;
use cxc::XcReflect;
#[derive(Default, Clone, Copy, Debug, XcReflect, PartialEq, Eq)]
pub struct Numbers5 {
pub a: i32,
pub b: i32,
pub c: i32,
pub d: i32,
pub e: i32,
}
#[test]
fn numbers_5() {
let mut unit = Unit::new();
unit.add_reflect_type::<Numbers5>();
unit.add_external_default::<Numbers5>();
unit.push_script(
"
some_numbers(); Numbers5 {
; Numbers5 { a = 4, b = 9, c = 39, ++ }
}
"
).unwrap();
let some_numbers = unit.get_fn("some_numbers").unwrap().downcast::<(), Numbers5>();
let numbers5 = some_numbers();
assert_eq!(numbers5, Numbers5 { a: 4, b: 9, c: 39, ..Default::default() });
}
Supports regular struct types, enums, tuples, function types, references, raw pointers, etc. AFAIK, the only thing it doesn't support it Unions, because those aren't in cxc. If there's anything that it doesn't support that you think it should, then please submit an issue
Dependencies
~1.5MB
~37K SLoC