mutable boxed types
Closed this issue · 2 comments
clegaard commented
What is the correct way to declare a mutable boxed type a function signature using #[ffi_export]?
Compiling with macro produces an error for the following piece of code:
#[ffi_export]
pub fn fmi2FreeInstance(mut slave: Option<repr_c::Box<Slave>>) {
match slave.as_mut() {
Some(s) => {
s.rpc.fmi2FreeInstance();
drop(slave)
}
None => {}
}
}
244 | pub fn fmi2FreeInstance(mut slave: Option<repr_c::Box<Slave>>) {
| ^^^^^ no rules expected this token in macro call
Without the macro the code compiles.
danielhenrymantilla commented
Not yet supported, but soon (say, in 2-3 weeks)! In the meantime, you'll need to do:
#[ffi_export]
- pub fn fmi2FreeInstance(mut slave: Option<repr_c::Box<Slave>>) {
+ pub fn fmi2FreeInstance( slave: Option<repr_c::Box<Slave>>) {
+ let mut slave = slave;
match slave.as_mut() {
Some(s) => {
s.rpc.fmi2FreeInstance();
drop(slave)
}
None => {}
}
}
clegaard commented
I see. I did not realize that it was possible to get a mutable "alias" to the boxed value inside the function.
Thank you for the quick response :)