"bitcoin::hash_types::Txid" if !is_ref => Some("crate::c_types::ThirtyTwoBytes"),
"bitcoin::hash_types::BlockHash" if is_ref => Some("*const [u8; 32]"),
"bitcoin::hash_types::BlockHash" if !is_ref => Some("crate::c_types::ThirtyTwoBytes"),
"bitcoin::hash_types::Txid" if !is_ref => Some("crate::c_types::ThirtyTwoBytes"),
"bitcoin::hash_types::BlockHash" if is_ref => Some("*const [u8; 32]"),
"bitcoin::hash_types::BlockHash" if !is_ref => Some("crate::c_types::ThirtyTwoBytes"),
"ln::channelmanager::PaymentHash" if is_ref => Some("*const [u8; 32]"),
"ln::channelmanager::PaymentHash" if !is_ref => Some("crate::c_types::ThirtyTwoBytes"),
"ln::channelmanager::PaymentPreimage" if is_ref => Some("*const [u8; 32]"),
"ln::channelmanager::PaymentHash" if is_ref => Some("*const [u8; 32]"),
"ln::channelmanager::PaymentHash" if !is_ref => Some("crate::c_types::ThirtyTwoBytes"),
"ln::channelmanager::PaymentPreimage" if is_ref => Some("*const [u8; 32]"),
"bitcoin::hash_types::Txid" if is_ref => Some(""),
"bitcoin::hash_types::BlockHash" if is_ref => Some(""),
"bitcoin::hash_types::BlockHash" => Some("crate::c_types::ThirtyTwoBytes { data: "),
"bitcoin::hash_types::Txid" if is_ref => Some(""),
"bitcoin::hash_types::BlockHash" if is_ref => Some(""),
"bitcoin::hash_types::BlockHash" => Some("crate::c_types::ThirtyTwoBytes { data: "),
"ln::channelmanager::PaymentHash" if is_ref => Some("&"),
"ln::channelmanager::PaymentHash" if !is_ref => Some("crate::c_types::ThirtyTwoBytes { data: "),
"ln::channelmanager::PaymentPreimage" if is_ref => Some("&"),
"ln::channelmanager::PaymentHash" if is_ref => Some("&"),
"ln::channelmanager::PaymentHash" if !is_ref => Some("crate::c_types::ThirtyTwoBytes { data: "),
"ln::channelmanager::PaymentPreimage" if is_ref => Some("&"),
"bitcoin::hash_types::Txid" if is_ref => Some(".as_inner()"),
"bitcoin::hash_types::BlockHash" if is_ref => Some(".as_inner()"),
"bitcoin::hash_types::BlockHash" => Some(".into_inner() }"),
"bitcoin::hash_types::Txid" if is_ref => Some(".as_inner()"),
"bitcoin::hash_types::BlockHash" if is_ref => Some(".as_inner()"),
"bitcoin::hash_types::BlockHash" => Some(".into_inner() }"),
"ln::channelmanager::PaymentHash" if is_ref => Some(".0"),
"ln::channelmanager::PaymentHash" => Some(".0 }"),
"ln::channelmanager::PaymentPreimage" if is_ref => Some(".0"),
"ln::channelmanager::PaymentHash" if is_ref => Some(".0"),
"ln::channelmanager::PaymentHash" => Some(".0 }"),
"ln::channelmanager::PaymentPreimage" if is_ref => Some(".0"),
self.write_c_mangled_container_path_intern(w, Self::path_to_generic_args(path), generics,
&format!("{}", single_ident_generic_path_to_ident(path).unwrap()), is_ref, false, false, false);
} else {
self.write_c_mangled_container_path_intern(w, Self::path_to_generic_args(path), generics,
&format!("{}", single_ident_generic_path_to_ident(path).unwrap()), is_ref, false, false, false);
} else {
- self.write_template_generics(w, &mut [$item].iter().map(|t| *t), is_ref, true);
+ self.write_template_generics(w, &mut [$item].iter().map(|t| *t), generics, is_ref, true);
}
} else if let syn::Type::Tuple(syn::TypeTuple { elems, .. }) = $item {
self.write_c_mangled_container_path_intern(w, elems.iter().collect(), generics,
&format!("{}Tuple", elems.len()), is_ref, false, false, false);
} else { unimplemented!(); }
write!(w, ") -> {} =\n\t{}::CResultTempl::<", mangled_container, Self::container_templ_path()).unwrap();
}
} else if let syn::Type::Tuple(syn::TypeTuple { elems, .. }) = $item {
self.write_c_mangled_container_path_intern(w, elems.iter().collect(), generics,
&format!("{}Tuple", elems.len()), is_ref, false, false, false);
} else { unimplemented!(); }
write!(w, ") -> {} =\n\t{}::CResultTempl::<", mangled_container, Self::container_templ_path()).unwrap();
- self.write_template_generics(w, &mut args.iter().map(|t| *t), is_ref, true);
+ self.write_template_generics(w, &mut args.iter().map(|t| *t), generics, is_ref, true);
- fn write_template_generics<'b, W: std::io::Write>(&self, w: &mut W, args: &mut dyn Iterator<Item=&'b syn::Type>, is_ref: bool, in_crate: bool) {
+ fn write_template_generics<'b, W: std::io::Write>(&self, w: &mut W, args: &mut dyn Iterator<Item=&'b syn::Type>, generics: Option<&GenericTypes>, is_ref: bool, in_crate: bool) {
for (idx, t) in args.enumerate() {
if idx != 0 {
write!(w, ", ").unwrap();
for (idx, t) in args.enumerate() {
if idx != 0 {
write!(w, ", ").unwrap();
write!(w, "u8").unwrap();
} else {
write!(w, "{}::C{}TupleTempl<", Self::container_templ_path(), tup.elems.len()).unwrap();
write!(w, "u8").unwrap();
} else {
write!(w, "{}::C{}TupleTempl<", Self::container_templ_path(), tup.elems.len()).unwrap();
- self.write_template_generics(w, &mut tup.elems.iter(), is_ref, in_crate);
+ self.write_template_generics(w, &mut tup.elems.iter(), generics, is_ref, in_crate);
if self.is_primitive(&resolved_generic) {
write!(w, "{}", resolved_generic).unwrap();
} else if let Some(c_type) = self.c_type_from_path(&resolved_generic, is_ref, false) {
if self.is_primitive(&resolved_generic) {
write!(w, "{}", resolved_generic).unwrap();
} else if let Some(c_type) = self.c_type_from_path(&resolved_generic, is_ref, false) {
if let syn::PathArguments::AngleBracketed(args) = &p_arg.path.segments.iter().next().unwrap().arguments {
self.write_template_generics(w, &mut args.args.iter().map(|gen|
if let syn::GenericArgument::Type(t) = gen { t } else { unimplemented!() }),
if let syn::PathArguments::AngleBracketed(args) = &p_arg.path.segments.iter().next().unwrap().arguments {
self.write_template_generics(w, &mut args.args.iter().map(|gen|
if let syn::GenericArgument::Type(t) = gen { t } else { unimplemented!() }),
} else { unimplemented!(); }
write!(w, ">").unwrap();
} else if resolved_generic == "Option" {
if let syn::PathArguments::AngleBracketed(args) = &p_arg.path.segments.iter().next().unwrap().arguments {
self.write_template_generics(w, &mut args.args.iter().map(|gen|
if let syn::GenericArgument::Type(t) = gen { t } else { unimplemented!() }),
} else { unimplemented!(); }
write!(w, ">").unwrap();
} else if resolved_generic == "Option" {
if let syn::PathArguments::AngleBracketed(args) = &p_arg.path.segments.iter().next().unwrap().arguments {
self.write_template_generics(w, &mut args.args.iter().map(|gen|
if let syn::GenericArgument::Type(t) = gen { t } else { unimplemented!() }),
} else { unimplemented!(); }
} else if in_crate {
write!(w, "{}", c_type).unwrap();
} else {
} else { unimplemented!(); }
} else if in_crate {
write!(w, "{}", c_type).unwrap();
} else {
if self.crate_types.opaques.get(&resolved).is_some() {
write!(w, "crate::{}", resolved).unwrap();
} else {
if self.crate_types.opaques.get(&resolved).is_some() {
write!(w, "crate::{}", resolved).unwrap();
} else {
} else { unimplemented!(); }
} else if let syn::Type::Array(a_arg) = t {
if let syn::Type::Path(p_arg) = &*a_arg.elem {
} else { unimplemented!(); }
} else if let syn::Type::Array(a_arg) = t {
if let syn::Type::Path(p_arg) = &*a_arg.elem {
assert!(self.is_primitive(&resolved));
if let syn::Expr::Lit(syn::ExprLit { lit: syn::Lit::Int(len), .. }) = &a_arg.len {
write!(w, "{}",
assert!(self.is_primitive(&resolved));
if let syn::Expr::Lit(syn::ExprLit { lit: syn::Lit::Int(len), .. }) = &a_arg.len {
write!(w, "{}",
write!(&mut created_container, "#[no_mangle]\npub type {} = ", mangled_container).unwrap();
write!(&mut created_container, "{}::C{}Templ<", Self::container_templ_path(), container_type).unwrap();
write!(&mut created_container, "#[no_mangle]\npub type {} = ", mangled_container).unwrap();
write!(&mut created_container, "{}::C{}Templ<", Self::container_templ_path(), container_type).unwrap();
- self.write_template_generics(&mut created_container, &mut args.iter().map(|t| *t), is_ref, true);
+ self.write_template_generics(&mut created_container, &mut args.iter().map(|t| *t), generics, is_ref, true);
writeln!(&mut created_container, ">;").unwrap();
write!(&mut created_container, "#[no_mangle]\npub static {}_free: extern \"C\" fn({}) = ", mangled_container, mangled_container).unwrap();
write!(&mut created_container, "{}::C{}Templ_free::<", Self::container_templ_path(), container_type).unwrap();
writeln!(&mut created_container, ">;").unwrap();
write!(&mut created_container, "#[no_mangle]\npub static {}_free: extern \"C\" fn({}) = ", mangled_container, mangled_container).unwrap();
write!(&mut created_container, "{}::C{}Templ_free::<", Self::container_templ_path(), container_type).unwrap();
- self.write_template_generics(&mut created_container, &mut args.iter().map(|t| *t), is_ref, true);
+ self.write_template_generics(&mut created_container, &mut args.iter().map(|t| *t), generics, is_ref, true);
writeln!(&mut created_container, ">;").unwrap();
self.write_template_constructor(&mut created_container, container_type, &mangled_container, &args, generics, is_ref);
writeln!(&mut created_container, ">;").unwrap();
self.write_template_constructor(&mut created_container, container_type, &mangled_container, &args, generics, is_ref);