Merge pull request #12 from TheBlueMatt/2021-04-incl-persister
[ldk-c-bindings] / c-bindings-gen / src / types.rs
index edd993f9be137fa45d752dc51d01ba6538fc30eb..7e4eee3798fc8643caf2d707a37eefbeee8ddf1b 100644 (file)
@@ -194,6 +194,7 @@ impl<'a, 'p: 'a> GenericTypes<'a, 'p> {
                                                        assert_simple_bound(&trait_bound);
                                                        if let Some(mut path) = types.maybe_resolve_path(&trait_bound.path, None) {
                                                                if types.skip_path(&path) { continue; }
+                                                               if path == "Sized" { continue; }
                                                                if non_lifetimes_processed { return false; }
                                                                non_lifetimes_processed = true;
                                                                let new_ident = if path != "std::ops::Deref" {
@@ -223,6 +224,9 @@ impl<'a, 'p: 'a> GenericTypes<'a, 'p> {
                                                        let mut non_lifetimes_processed = false;
                                                        for bound in t.bounds.iter() {
                                                                if let syn::TypeParamBound::Trait(trait_bound) = bound {
+                                                                       if let Some(id) = trait_bound.path.get_ident() {
+                                                                               if format!("{}", id) == "Sized" { continue; }
+                                                                       }
                                                                        if non_lifetimes_processed { return false; }
                                                                        non_lifetimes_processed = true;
                                                                        assert_simple_bound(&trait_bound);
@@ -509,7 +513,10 @@ impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'cr
                        let remaining: String = seg_iter.map(|seg| {
                                format!("::{}", seg.ident)
                        }).collect();
-                       if let Some((imp, _)) = self.imports.get(&first_seg.ident) {
+                       let first_seg_str = format!("{}", first_seg.ident);
+                       if first_seg_str == "std" {
+                               Some(first_seg_str + &remaining)
+                       } else if let Some((imp, _)) = self.imports.get(&first_seg.ident) {
                                if remaining != "" {
                                        Some(imp.clone() + &remaining)
                                } else {
@@ -771,6 +778,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
                        "String" if is_ref => Some("crate::c_types::Str"),
 
                        "std::time::Duration" => Some("u64"),
+                       "std::io::Error" => Some("crate::c_types::IOError"),
 
                        "bitcoin::secp256k1::key::PublicKey" => Some("crate::c_types::PublicKey"),
                        "bitcoin::secp256k1::Signature" => Some("crate::c_types::Signature"),
@@ -963,6 +971,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
                        "String" => Some(""),
 
                        "std::time::Duration" => Some(""),
+                       "std::io::Error" if !is_ref => Some("crate::c_types::IOError::from_rust("),
 
                        "bitcoin::secp256k1::key::PublicKey" => Some("crate::c_types::PublicKey::from_rust(&"),
                        "bitcoin::secp256k1::Signature" => Some("crate::c_types::Signature::from_rust(&"),
@@ -1021,6 +1030,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
                        "String" if is_ref => Some(".as_str().into()"),
 
                        "std::time::Duration" => Some(".as_secs()"),
+                       "std::io::Error" if !is_ref => Some(")"),
 
                        "bitcoin::secp256k1::key::PublicKey" => Some(")"),
                        "bitcoin::secp256k1::Signature" => Some(")"),