Skip to content

Commit f7f26a1

Browse files
committed
Support serialization impls defined in a diff module from the type
1 parent 3f6f425 commit f7f26a1

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

c-bindings-gen/src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,22 @@ fn maybe_convert_trait_impl<W: std::io::Write>(w: &mut W, trait_path: &syn::Path
6262
if let Some(t) = types.maybe_resolve_path(&trait_path, Some(generics)) {
6363
let for_obj;
6464
let full_obj_path;
65+
let native_path;
6566
let mut has_inner = false;
6667
if let syn::Type::Path(ref p) = for_ty {
6768
let resolved_path = types.resolve_path(&p.path, Some(generics));
6869
for_obj = format!("{}", p.path.segments.last().unwrap().ident);
6970
full_obj_path = format!("crate::{}", resolved_path);
7071
has_inner = types.c_type_has_inner_from_path(&resolved_path);
72+
let (path, name) = full_obj_path.rsplit_once("::").unwrap();
73+
native_path = path.to_string() + "::native" + name;
7174
} else {
7275
// We assume that anything that isn't a Path is somehow a generic that ends up in our
7376
// derived-types module.
7477
let mut for_obj_vec = Vec::new();
7578
types.write_c_type(&mut for_obj_vec, for_ty, Some(generics), false);
7679
full_obj_path = String::from_utf8(for_obj_vec).unwrap();
80+
native_path = full_obj_path.clone();
7781
if !full_obj_path.starts_with(TypeResolver::generated_container_path()) { return; }
7882
for_obj = full_obj_path[TypeResolver::generated_container_path().len() + 2..].into();
7983
}
@@ -98,7 +102,7 @@ fn maybe_convert_trait_impl<W: std::io::Write>(w: &mut W, trait_path: &syn::Path
98102
writeln!(w, "#[allow(unused)]").unwrap();
99103
writeln!(w, "pub(crate) extern \"C\" fn {}_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {{", for_obj).unwrap();
100104
if has_inner {
101-
writeln!(w, "\tcrate::c_types::serialize_obj(unsafe {{ &*(obj as *const native{}) }})", for_obj).unwrap();
105+
writeln!(w, "\tcrate::c_types::serialize_obj(unsafe {{ &*(obj as *const {}) }})", native_path).unwrap();
102106
} else {
103107
writeln!(w, "\t{}_write(unsafe {{ &*(obj as *const {}) }})", for_obj, for_obj).unwrap();
104108
}

0 commit comments

Comments
 (0)