// *** Per-Type Printing Logic ***
// *******************************
-macro_rules! walk_supertraits { ($t: expr, $types: expr, ($( $pat: pat => $e: expr),*) ) => { {
+macro_rules! walk_supertraits { ($t: expr, $types: expr, ($( $($pat: pat)|* => $e: expr),*) ) => { {
if $t.colon_token.is_some() {
for st in $t.supertraits.iter() {
match st {
if let Some(types) = types_opt {
if let Some(path) = types.maybe_resolve_path(&supertrait.path, None) {
match (&path as &str, &supertrait.path.segments.iter().last().unwrap().ident) {
- $( $pat => $e, )*
+ $( $($pat)|* => $e, )*
}
continue;
}
}
if let Some(ident) = supertrait.path.get_ident() {
match (&format!("{}", ident) as &str, &ident) {
- $( $pat => $e, )*
+ $( $($pat)|* => $e, )*
}
} else if types_opt.is_some() {
panic!("Supertrait unresolvable and not single-ident");
writeln!(w, "\tpub clone: Option<extern \"C\" fn (this_arg: *const c_void) -> *mut c_void>,").unwrap();
generated_fields.push(("clone".to_owned(), true));
},
- ("std::cmp::Eq", _) => {
+ ("std::cmp::Eq", _)|("core::cmp::Eq", _) => {
writeln!(w, "\t/// Checks if two objects are equal given this object's this_arg pointer and another object.").unwrap();
writeln!(w, "\tpub eq: extern \"C\" fn (this_arg: *const c_void, other_arg: &{}) -> bool,", trait_name).unwrap();
writeln!(extra_headers, "typedef struct LDK{} LDK{};", trait_name, trait_name).unwrap();
generated_fields.push(("eq".to_owned(), true));
},
- ("std::hash::Hash", _) => {
+ ("std::hash::Hash", _)|("core::hash::Hash", _) => {
writeln!(w, "\t/// Calculate a succinct non-cryptographic hash for an object given its this_arg pointer.").unwrap();
writeln!(w, "\t/// This is used, for example, for inclusion of this object in a hash map.").unwrap();
writeln!(w, "\tpub hash: extern \"C\" fn (this_arg: *const c_void) -> u64,").unwrap();
walk_supertraits!(t, Some(&types), (
("Send", _) => writeln!(w, "unsafe impl Send for {} {{}}", trait_name).unwrap(),
("Sync", _) => writeln!(w, "unsafe impl Sync for {} {{}}", trait_name).unwrap(),
- ("std::cmp::Eq", _) => {
+ ("std::cmp::Eq", _)|("core::cmp::Eq", _) => {
writeln!(w, "impl std::cmp::Eq for {} {{}}", trait_name).unwrap();
writeln!(w, "impl std::cmp::PartialEq for {} {{", trait_name).unwrap();
writeln!(w, "\tfn eq(&self, o: &Self) -> bool {{ (self.eq)(self.this_arg, o) }}\n}}").unwrap();
},
- ("std::hash::Hash", _) => {
+ ("std::hash::Hash", _)|("core::hash::Hash", _) => {
writeln!(w, "impl std::hash::Hash for {} {{", trait_name).unwrap();
writeln!(w, "\tfn hash<H: std::hash::Hasher>(&self, hasher: &mut H) {{ hasher.write_u64((self.hash)(self.this_arg)) }}\n}}").unwrap();
},
if path == "Sized" { continue; }
if non_lifetimes_processed { return false; }
non_lifetimes_processed = true;
- let new_ident = if path != "std::ops::Deref" {
+ let new_ident = if path != "std::ops::Deref" && path != "core::ops::Deref" {
path = "crate::".to_string() + &path;
Some(&trait_bound.path)
} else { None };
if p.path.leading_colon.is_some() { return false; }
let mut p_iter = p.path.segments.iter();
if let Some(gen) = self.typed_generics.get_mut(&p_iter.next().unwrap().ident) {
- if gen.0 != "std::ops::Deref" { return false; }
+ if gen.0 != "std::ops::Deref" && gen.0 != "core::ops::Deref" { return false; }
if &format!("{}", p_iter.next().unwrap().ident) != "Target" { return false; }
let mut non_lifetimes_processed = false;
// implement Deref<Target=Self> for relevant types). We don't
// bother to implement it for associated types, however, so we just
// ignore such bounds.
- let new_ident = if path != "std::ops::Deref" {
+ let new_ident = if path != "std::ops::Deref" && path != "core::ops::Deref" {
path = "crate::".to_string() + &path;
Some(&tr.path)
} else { None };
"[u8; 3]" if !is_ref => Some("crate::c_types::ThreeBytes"), // Used for RGB values
"str" if is_ref => Some("crate::c_types::Str"),
- "String" => Some("crate::c_types::Str"),
+ "alloc::string::String"|"String" => Some("crate::c_types::Str"),
- "std::time::Duration" => Some("u64"),
+ "std::time::Duration"|"core::time::Duration" => Some("u64"),
"std::time::SystemTime" => Some("u64"),
"std::io::Error" => Some("crate::c_types::IOError"),
"[usize]" if is_ref => Some(""),
"str" if is_ref => Some(""),
- "String" => Some(""),
+ "alloc::string::String"|"String" => Some(""),
// Note that we'll panic for String if is_ref, as we only have non-owned memory, we
// cannot create a &String.
- "std::time::Duration" => Some("std::time::Duration::from_secs("),
+ "std::time::Duration"|"core::time::Duration" => Some("std::time::Duration::from_secs("),
"std::time::SystemTime" => Some("(::std::time::SystemTime::UNIX_EPOCH + std::time::Duration::from_secs("),
"bech32::u5" => Some(""),
"[usize]" if is_ref => Some(".to_slice()"),
"str" if is_ref => Some(".into_str()"),
- "String" => Some(".into_string()"),
+ "alloc::string::String"|"String" => Some(".into_string()"),
- "std::time::Duration" => Some(")"),
+ "std::time::Duration"|"core::time::Duration" => Some(")"),
"std::time::SystemTime" => Some("))"),
"bech32::u5" => Some(".into()"),
"[usize]" if is_ref => Some("local_"),
"str" if is_ref => Some(""),
- "String" => Some(""),
+ "alloc::string::String"|"String" => Some(""),
- "std::time::Duration" => Some(""),
+ "std::time::Duration"|"core::time::Duration" => Some(""),
"std::time::SystemTime" => Some(""),
"std::io::Error" if !is_ref => Some("crate::c_types::IOError::from_rust("),
"[usize]" if is_ref => Some(""),
"str" if is_ref => Some(".into()"),
- "String" if is_ref => Some(".as_str().into()"),
- "String" => Some(".into()"),
+ "alloc::string::String"|"String" if is_ref => Some(".as_str().into()"),
+ "alloc::string::String"|"String" => Some(".into()"),
- "std::time::Duration" => Some(".as_secs()"),
+ "std::time::Duration"|"core::time::Duration" => Some(".as_secs()"),
"std::time::SystemTime" => Some(".duration_since(::std::time::SystemTime::UNIX_EPOCH).expect(\"Times must be post-1970\").as_secs()"),
"std::io::Error" if !is_ref => Some(")"),