for inp in sig.inputs.iter() {
match inp {
syn::FnArg::Receiver(recv) => {
- if !recv.attrs.is_empty() || recv.reference.is_none() { unimplemented!(); }
- write!(w, "this_arg: {}{}",
- match (self_ptr, recv.mutability.is_some()) {
- (true, true) => "*mut ",
- (true, false) => "*const ",
- (false, true) => "&mut ",
- (false, false) => "&",
- }, this_param).unwrap();
+ if !recv.attrs.is_empty() { unimplemented!(); }
+ write!(w, "{}this_arg: {}{}", if recv.reference.is_none() { "mut " } else { "" },
+ if recv.reference.is_some() {
+ match (self_ptr, recv.mutability.is_some()) {
+ (true, true) => "*mut ",
+ (true, false) => "*const ",
+ (false, true) => "&mut ",
+ (false, false) => "&",
+ }
+ } else { "" }, this_param).unwrap();
assert!(first_arg);
first_arg = false;
},
for inp in sig.inputs.iter() {
match inp {
syn::FnArg::Receiver(recv) => {
- if !recv.attrs.is_empty() || recv.reference.is_none() { unimplemented!(); }
+ if !recv.attrs.is_empty() { unimplemented!(); }
if to_c {
+ if recv.reference.is_none() { unimplemented!(); }
write!(w, "self.this_arg").unwrap();
first_arg = false;
}
write_method_var_decl_body(w, &m.sig, "", types, Some(&meth_gen_types), false);
let mut takes_self = false;
let mut takes_mut_self = false;
+ let mut takes_owned_self = false;
for inp in m.sig.inputs.iter() {
if let syn::FnArg::Receiver(r) = inp {
takes_self = true;
if r.mutability.is_some() { takes_mut_self = true; }
+ if r.reference.is_none() { takes_owned_self = true; }
}
}
if !takes_mut_self && !takes_self {
match &declared_type {
DeclType::MirroredEnum => write!(w, "this_arg.to_native().{}(", m.sig.ident).unwrap(),
DeclType::StructImported => {
- if takes_mut_self {
+ if takes_owned_self {
+ write!(w, "(*unsafe {{ Box::from_raw(this_arg.take_inner()) }}).{}(", m.sig.ident).unwrap();
+ } else if takes_mut_self {
write!(w, "unsafe {{ &mut (*(this_arg.inner as *mut native{})) }}.{}(", ident, m.sig.ident).unwrap();
} else {
write!(w, "unsafe {{ &*this_arg.inner }}.{}(", m.sig.ident).unwrap();