#[derive(C)]
Expand description
对C语言的增加处理方法
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
e-macros = { version = "0.1", git="https://gitee.com/eternalnight996/e-macros"}
§Example
#[derive(e_utils::C)]
struct B {
d: i32,
f: String,
}
fn test() -> Result<()> {
// 假设我们有一个T类型的实例
let value: B = B {
d: 1,
f: "test".to_string(),
};
let ptr = value.to_c_ptr();
// 还原*c_void指针为<Box<T>>实例
if let Some(restored_boxed_value) = unsafe { B::from_c_ptr(ptr) } {
// 成功还原Box<T>实例
println!("Restored value: {:?}", *restored_boxed_value);
} else {
// 还原过程中出现错误
println!("Failed to restore value");
}
Ok(())
}