X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=ldk-c-bindings;a=blobdiff_plain;f=c-bindings-gen%2Fsrc%2Ftypes.rs;fp=c-bindings-gen%2Fsrc%2Ftypes.rs;h=bc42bda05c614ccaf3b20e7673d3f877e0fd3f35;hp=e45fdca095ddb5552cb72f95d81bc631af2b0ff1;hb=b7defa46972f319f4bc86fc30900862c1a459f71;hpb=dda9d452eb175033fa8ecb29f2396c79a05162cb diff --git a/c-bindings-gen/src/types.rs b/c-bindings-gen/src/types.rs index e45fdca..bc42bda 100644 --- a/c-bindings-gen/src/types.rs +++ b/c-bindings-gen/src/types.rs @@ -864,6 +864,8 @@ pub struct CrateTypes<'a> { clonable_types: RefCell>, /// Key impls Value pub trait_impls: HashMap>, + /// Value impls Key + pub traits_impld: HashMap>, /// The full set of modules in the crate(s) pub lib_ast: &'a FullLibraryAST, } @@ -874,7 +876,8 @@ impl<'a> CrateTypes<'a> { opaques: HashMap::new(), mirrored_enums: HashMap::new(), traits: HashMap::new(), type_aliases: HashMap::new(), reverse_alias_map: HashMap::new(), templates_defined: RefCell::new(HashMap::default()), priv_structs: HashMap::new(), - clonable_types: RefCell::new(initial_clonable_types()), trait_impls: HashMap::new(), + clonable_types: RefCell::new(initial_clonable_types()), + trait_impls: HashMap::new(), traits_impld: HashMap::new(), template_file: RefCell::new(template_file), lib_ast: &libast, } } @@ -2131,7 +2134,19 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> { if let Some(decl_type) = self.types.maybe_resolve_declared(ident) { decl_lookup(w, decl_type, &self.maybe_resolve_ident(ident).unwrap(), is_ref, is_mut); } else { unimplemented!(); } - } else { unimplemented!(); } + } else { + if let Some(trait_impls) = self.crate_types.traits_impld.get(&resolved_path) { + if trait_impls.len() == 1 { + // If this is a no-export'd crate and there's only one implementation + // in the whole crate, just treat it as a reference to whatever the + // implementor is. + let implementor = self.crate_types.opaques.get(&trait_impls[0]).unwrap(); + decl_lookup(w, &DeclType::StructImported { generics: &implementor.1 }, &trait_impls[0], true, is_mut); + return; + } + } + unimplemented!(); + } }, syn::Type::Array(a) => { if let syn::Type::Path(p) = &*a.elem { @@ -2969,6 +2984,18 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> { } true } else { + if let Some(trait_impls) = self.crate_types.traits_impld.get(&full_path) { + if trait_impls.len() == 1 { + // If this is a no-export'd crate and there's only one implementation in the + // whole crate, just treat it as a reference to whatever the implementor is. + if with_ref_lifetime { + write!(w, "&'static crate::{}", trait_impls[0]).unwrap(); + } else { + write!(w, "&crate::{}", trait_impls[0]).unwrap(); + } + return true; + } + } false } }