ident.mutability.is_some() || ident.subpat.is_some() {
unimplemented!();
}
- write!(w, ", {}{}: ", if $type_resolver.skip_arg(&*arg.ty, Some(&meth_gen_types)) { "_" } else { "" }, ident.ident).unwrap();
+ write!(w, ", mut {}{}: ", if $type_resolver.skip_arg(&*arg.ty, Some(&meth_gen_types)) { "_" } else { "" }, ident.ident).unwrap();
}
_ => unimplemented!(),
}
writeln!(w, "#[no_mangle]").unwrap();
writeln!(w, "/// Read a {} object from a string", ident).unwrap();
writeln!(w, "pub extern \"C\" fn {}_from_str(s: crate::c_types::Str) -> {} {{", ident, container).unwrap();
- writeln!(w, "\tmatch {}::from_str(s.into()) {{", resolved_path).unwrap();
+ writeln!(w, "\tmatch {}::from_str(s.into_str()) {{", resolved_path).unwrap();
writeln!(w, "\t\tOk(r) => {{").unwrap();
- let new_var = types.write_to_c_conversion_new_var(w, &syn::Ident::new("r", Span::call_site()), &*i.self_ty, Some(&gen_types), false);
+ let new_var = types.write_to_c_conversion_new_var(w, &format_ident!("r"), &*i.self_ty, Some(&gen_types), false);
write!(w, "\t\t\tcrate::c_types::CResultTempl::ok(\n\t\t\t\t").unwrap();
types.write_to_c_conversion_inline_prefix(w, &*i.self_ty, Some(&gen_types), false);
write!(w, "{}r", if new_var { "local_" } else { "" }).unwrap();
types.write_to_c_conversion_inline_suffix(w, &*i.self_ty, Some(&gen_types), false);
writeln!(w, "\n\t\t\t)\n\t\t}},").unwrap();
- writeln!(w, "\t\tErr(e) => crate::c_types::CResultTempl::err(0u8),").unwrap();
+ writeln!(w, "\t\tErr(e) => crate::c_types::CResultTempl::err(()),").unwrap();
writeln!(w, "\t}}.into()\n}}").unwrap();
}
} else if path_matches_nongeneric(&trait_path.1, &["Display"]) {
writeln!(w, "#[no_mangle]").unwrap();
writeln!(w, "/// Get the string representation of a {} object", ident).unwrap();
- writeln!(w, "pub extern \"C\" fn {}_to_str(o: &{}) -> Str {{", ident, resolved_path).unwrap();
- writeln!(w, "\tformat!(\"{{}}\", o).into()").unwrap();
+ writeln!(w, "pub extern \"C\" fn {}_to_str(o: &crate::{}) -> Str {{", ident, resolved_path).unwrap();
+
+ let self_ty = &i.self_ty;
+ let ref_type: syn::Type = syn::parse_quote!(&#self_ty);
+ let new_var = types.write_from_c_conversion_new_var(w, &format_ident!("o"), &ref_type, Some(&gen_types));
+ write!(w, "\tformat!(\"{{}}\", ").unwrap();
+ types.write_from_c_conversion_prefix(w, &ref_type, Some(&gen_types));
+ write!(w, "{}o", if new_var { "local_" } else { "" }).unwrap();
+ types.write_from_c_conversion_suffix(w, &ref_type, Some(&gen_types));
+ writeln!(w, ").into()").unwrap();
+
writeln!(w, "}}").unwrap();
} else {
//XXX: implement for other things like ToString
}
writeln_docs(w, &e.attrs, "");
- if e.generics.lt_token.is_some() {
- unimplemented!();
- }
+ let mut gen_types = GenericTypes::new(None);
+ assert!(gen_types.learn_generics(&e.generics, types));
let mut needs_free = false;
if export_status(&field.attrs) == ExportStatus::TestOnly { continue; }
writeln_docs(w, &field.attrs, "\t\t");
write!(w, "\t\t{}: ", field.ident.as_ref().unwrap()).unwrap();
- types.write_c_type(w, &field.ty, None, false);
+ types.write_c_type(w, &field.ty, Some(&gen_types), false);
writeln!(w, ",").unwrap();
}
write!(w, "\t}}").unwrap();
write!(w, "(").unwrap();
for (idx, field) in fields.unnamed.iter().enumerate() {
if export_status(&field.attrs) == ExportStatus::TestOnly { continue; }
- types.write_c_type(w, &field.ty, None, false);
+ types.write_c_type(w, &field.ty, Some(&gen_types), false);
if idx != fields.unnamed.len() - 1 {
write!(w, ",").unwrap();
}
let mut sink = ::std::io::sink();
let mut out: &mut dyn std::io::Write = if $ref { &mut sink } else { w };
let new_var = if $to_c {
- types.write_to_c_conversion_new_var(&mut out, $field_ident, &$field.ty, None, false)
+ types.write_to_c_conversion_new_var(&mut out, $field_ident, &$field.ty, Some(&gen_types), false)
} else {
- types.write_from_c_conversion_new_var(&mut out, $field_ident, &$field.ty, None)
+ types.write_from_c_conversion_new_var(&mut out, $field_ident, &$field.ty, Some(&gen_types))
};
if $ref || new_var {
if $ref {
if new_var {
let nonref_ident = format_ident!("{}_nonref", $field_ident);
if $to_c {
- types.write_to_c_conversion_new_var(w, &nonref_ident, &$field.ty, None, false);
+ types.write_to_c_conversion_new_var(w, &nonref_ident, &$field.ty, Some(&gen_types), false);
} else {
- types.write_from_c_conversion_new_var(w, &nonref_ident, &$field.ty, None);
+ types.write_from_c_conversion_new_var(w, &nonref_ident, &$field.ty, Some(&gen_types));
}
write!(w, "\n\t\t\t\t").unwrap();
}
($field: expr, $field_ident: expr) => { {
if export_status(&$field.attrs) == ExportStatus::TestOnly { continue; }
if $to_c {
- types.write_to_c_conversion_inline_prefix(w, &$field.ty, None, false);
+ types.write_to_c_conversion_inline_prefix(w, &$field.ty, Some(&gen_types), false);
} else {
- types.write_from_c_conversion_prefix(w, &$field.ty, None);
+ types.write_from_c_conversion_prefix(w, &$field.ty, Some(&gen_types));
}
write!(w, "{}{}", $field_ident,
if $ref { "_nonref" } else { "" }).unwrap();
if $to_c {
- types.write_to_c_conversion_inline_suffix(w, &$field.ty, None, false);
+ types.write_to_c_conversion_inline_suffix(w, &$field.ty, Some(&gen_types), false);
} else {
- types.write_from_c_conversion_suffix(w, &$field.ty, None);
+ types.write_from_c_conversion_suffix(w, &$field.ty, Some(&gen_types));
}
write!(w, ",").unwrap();
} }
writeln!(out, "#![allow(unused_parens)]").unwrap();
writeln!(out, "#![allow(unused_unsafe)]").unwrap();
writeln!(out, "#![allow(unused_braces)]").unwrap();
- writeln!(out, "#![deny(missing_docs)]").unwrap();
+ // TODO: We need to map deny(missing_docs) in the source crate(s)
+ //writeln!(out, "#![deny(missing_docs)]").unwrap();
writeln!(out, "pub mod c_types;").unwrap();
writeln!(out, "pub mod bitcoin;").unwrap();
} else {