Skip to content

Commit 28b0ccf

Browse files
committed
Add support for implementing traits with a Debug requirement
1 parent 349213a commit 28b0ccf

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

c-bindings-gen/src/main.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,9 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa
11011101
},
11021102
("Sync", _, _) => {}, ("Send", _, _) => {},
11031103
("std::marker::Sync", _, _) => {}, ("std::marker::Send", _, _) => {},
1104-
("core::fmt::Debug", _, _) => {},
1104+
("core::fmt::Debug", _, _) => {
1105+
writeln!(w, "\t\tdebug_str: {}_debug_str_void,", ident).unwrap();
1106+
},
11051107
(s, t, _) => {
11061108
if let Some(supertrait_obj) = types.crate_types.traits.get(s) {
11071109
macro_rules! write_impl_fields {
@@ -1399,6 +1401,12 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa
13991401

14001402
writeln!(w, "\t}}.into()\n}}").unwrap();
14011403
}
1404+
} else if path_matches_nongeneric(&trait_path.1, &["core", "fmt", "Debug"]) {
1405+
writeln!(w, "/// Get a string which allows debug introspection of a {} object", ident).unwrap();
1406+
writeln!(w, "pub extern \"C\" fn {}_debug_str_void(o: *const c_void) -> Str {{", ident).unwrap();
1407+
1408+
write!(w, "\talloc::format!(\"{{:?}}\", unsafe {{ o as *const crate::{} }}).into()", resolved_path).unwrap();
1409+
writeln!(w, "}}").unwrap();
14021410
} else if path_matches_nongeneric(&trait_path.1, &["Display"]) {
14031411
writeln!(w, "#[no_mangle]").unwrap();
14041412
writeln!(w, "/// Get the string representation of a {} object", ident).unwrap();

0 commit comments

Comments
 (0)