/// type), otherwise it is mapped into a transparent, C-compatible version of itself.
pub fn is_enum_opaque(e: &syn::ItemEnum) -> bool {
for var in e.variants.iter() {
- if let syn::Fields::Unit = var.fields {
- } else if let syn::Fields::Named(fields) = &var.fields {
+ if let syn::Fields::Named(fields) = &var.fields {
for field in fields.named.iter() {
match export_status(&field.attrs) {
ExportStatus::Export|ExportStatus::TestOnly => {},
ExportStatus::NoExport => return true,
}
}
- } else {
- return true;
+ } else if let syn::Fields::Unnamed(fields) = &var.fields {
+ for field in fields.unnamed.iter() {
+ match export_status(&field.attrs) {
+ ExportStatus::Export|ExportStatus::TestOnly => {},
+ ExportStatus::NoExport => return true,
+ }
+ }
}
}
false
/// Returns true we if can just skip passing this to C entirely
fn no_arg_path_to_rust(&self, full_path: &str) -> &str {
if full_path == "bitcoin::secp256k1::Secp256k1" {
- "&bitcoin::secp256k1::Secp256k1::new()"
+ "secp256k1::SECP256K1"
} else { unimplemented!(); }
}
}
/// Gets the C-mapped type for types which are outside of the crate, or which are manually
/// ignored by for some reason need mapping anyway.
- fn c_type_from_path<'b>(&self, full_path: &'b str, is_ref: bool, ptr_for_ref: bool) -> Option<&'b str> {
+ fn c_type_from_path<'b>(&self, full_path: &'b str, is_ref: bool, _ptr_for_ref: bool) -> Option<&'b str> {
if self.is_primitive(full_path) {
return Some(full_path);
}
_ => None,
}.map(|s| s.to_owned())
}
- fn to_c_conversion_inline_prefix_from_path(&self, full_path: &str, is_ref: bool, ptr_for_ref: bool) -> Option<String> {
+ fn to_c_conversion_inline_prefix_from_path(&self, full_path: &str, is_ref: bool, _ptr_for_ref: bool) -> Option<String> {
if self.is_primitive(full_path) {
return Some("".to_owned());
}
"bitcoin::blockdata::transaction::Transaction" => Some("crate::c_types::Transaction::from_vec(local_"),
"bitcoin::blockdata::transaction::OutPoint" => Some("crate::c_types::bitcoin_to_C_outpoint("),
"bitcoin::blockdata::transaction::TxOut" if !is_ref => Some("crate::c_types::TxOut::from_rust("),
+ "bitcoin::network::constants::Network" => Some("crate::bitcoin::network::Network::from_bitcoin("),
"bitcoin::blockdata::block::BlockHeader" if is_ref => Some("&local_"),
"bitcoin::blockdata::block::Block" if is_ref => Some("crate::c_types::u8slice::from_slice(&local_"),
_ => None,
}.map(|s| s.to_owned())
}
- fn to_c_conversion_inline_suffix_from_path(&self, full_path: &str, is_ref: bool, ptr_for_ref: bool) -> Option<String> {
+ fn to_c_conversion_inline_suffix_from_path(&self, full_path: &str, is_ref: bool, _ptr_for_ref: bool) -> Option<String> {
if self.is_primitive(full_path) {
return Some("".to_owned());
}
"bitcoin::blockdata::transaction::Transaction" => Some(")"),
"bitcoin::blockdata::transaction::OutPoint" => Some(")"),
"bitcoin::blockdata::transaction::TxOut" if !is_ref => Some(")"),
+ "bitcoin::network::constants::Network" => Some(")"),
"bitcoin::blockdata::block::BlockHeader" if is_ref => Some(""),
"bitcoin::blockdata::block::Block" if is_ref => Some(")"),
").into() }"))
},
"Vec" if !is_ref => {
- Some(("Vec::new(); for item in ", vec![(format!(".drain(..) {{ local_{}.push(", var_name), "item".to_string())], "); }"))
+ Some(("Vec::new(); for mut item in ", vec![(format!(".drain(..) {{ local_{}.push(", var_name), "item".to_string())], "); }"))
},
"Slice" => {
Some(("Vec::new(); for item in ", vec![(format!(".iter() {{ local_{}.push(", var_name), "**item".to_string())], "); }"))
match full_path {
"Result" if !is_ref => {
Some(("match ",
- vec![(".result_ok { true => Ok(".to_string(), format!("(*unsafe {{ Box::from_raw(<*mut _>::take_ptr(&mut {}.contents.result)) }})", var_name)),
- ("), false => Err(".to_string(), format!("(*unsafe {{ Box::from_raw(<*mut _>::take_ptr(&mut {}.contents.err)) }})", var_name))],
+ vec![(".result_ok { true => Ok(".to_string(), format!("(*unsafe {{ Box::from_raw(<*mut _>::take_ptr(&mut {}.contents.result)) }})", var_access)),
+ ("), false => Err(".to_string(), format!("(*unsafe {{ Box::from_raw(<*mut _>::take_ptr(&mut {}.contents.err)) }})", var_access))],
")}"))
},
"Vec"|"Slice" if !is_ref => {
if let Some(syn::Type::Path(p)) = single_contained {
if self.c_type_has_inner_from_path(&self.resolve_path(&p.path, generics)) {
if is_ref {
- return Some(("if ", vec![(".inner.is_null() { None } else { Some((*".to_string(), format!("{}", var_name))], ").clone()) }"))
+ return Some(("if ", vec![(".inner.is_null() { None } else { Some((*".to_string(), format!("{}", var_access))], ").clone()) }"))
} else {
- return Some(("if ", vec![(".inner.is_null() { None } else { Some(".to_string(), format!("{}", var_name))], ") }"));
+ return Some(("if ", vec![(".inner.is_null() { None } else { Some(".to_string(), format!("{}", var_access))], ") }"));
}
}
}
if !self.write_c_path_intern(w, &$p_arg.path, generics, true, true, true) { return false; }
}
} else {
- if $p_arg.path.segments.len() == 1 {
- write!(w, "{}", $p_arg.path.segments.iter().next().unwrap().ident).unwrap();
- } else {
- return false;
- }
+ write!(w, "{}", $p_arg.path.segments.last().unwrap().ident).unwrap();
}
} else if self.is_known_container(&subtype, is_ref) || self.is_transparent_container(&subtype, is_ref) {
if !self.write_c_mangled_container_path_intern(w, Self::path_to_generic_args(&$p_arg.path), generics,