Generate Debug for sys types - #488
Conversation
|
All green. :) |
| try!(writeln!( | ||
| w, | ||
| "{comment}#[repr(C)]\n{comment}pub struct {name} {{", | ||
| "{comment}#[repr(C)]\n{debug}{comment}pub struct {name} {{", |
There was a problem hiding this comment.
This line seems generated struct with extra line:
#[repr(C)]
pub struct AtkAttribute {
pub name: *mut c_char,
pub value: *mut c_char,
}
There was a problem hiding this comment.
Wo. Where does this backline comes from? Oo
| {fields_name})\n\ | ||
| \t}}\n\ | ||
| }}\n", | ||
| name = klass.c_type, |
There was a problem hiding this comment.
Sorry, but this unreadable, and seems repeated at minimum twice.
There was a problem hiding this comment.
True. I'll write a function and maybe comment or create temporary variables in order to make this less horrible.
| try!(writeln!( | ||
| w, | ||
| "{}#[repr(C)]\n{0}pub struct {} {{", | ||
| "{}#[repr(C)]\n{}\n{0}pub struct {} {{", |
6f120d0 to
3283e71
Compare
| \t\twrite!(f, \"{name} @ {{:?}}\", self as *const _)\n\ | ||
| \t}}\n\ | ||
| }}\n", | ||
| name=record.c_type)); |
There was a problem hiding this comment.
IMHO this better extract as function too and maybe use raw string for format
|
This intended that inner fields not comma-separated? |
|
Hum yes. Do you want comma? |
|
Then its normal, just strange. |
|
I'll add the comma tomorrow then. ;) |
3283e71 to
5a15289
Compare
|
Updated. |
|
For printing things struct-like, please use the functions from Formatter like debug_struct() |
| w, | ||
| name, | ||
| &format!( | ||
| "write!(f, \"{name} @ {{:?}} {{{{ {fields}}}}}\",\n\ |
There was a problem hiding this comment.
IMHO extra space needed {{{{ {fields} }}}}
| impl_content) | ||
| } | ||
|
|
||
| fn generate_fields_with_debug(w: &mut Write, name: &str, lines: &[String]) -> Result<()> { |
There was a problem hiding this comment.
Not generate_debug_with_fields?
|
Updated and improved. Thanks for the suggestion @sdroege! |
| } else { | ||
| let field_name = field.split(":").next().unwrap().trim().replace("pub ", ""); | ||
| Some(if field.replace(",", "").trim().ends_with("c_void") { | ||
| format!("\t\t .field(\"{name}\", &\"c_void\")\n", name=field_name) |
There was a problem hiding this comment.
Is really need write constant string in debug result?
There was a problem hiding this comment.
I meant: maybe better just skip this field?
Current results:
//gobject
impl ::std::fmt::Debug for GParamSpecString {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
f.debug_struct(&format!("GParamSpecString @ {:?}", self as *const _))
.field("parent_instance", &self.parent_instance)
.field("default_value", &self.default_value)
.field("cset_first", &self.cset_first)
.field("cset_nth", &self.cset_nth)
.field("substitutor", &self.substitutor)
.field("_truncated_record_marker", &"c_void")
.finish()
}
}
//gtk
impl ::std::fmt::Debug for GtkRcStyle {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
f.debug_struct(&format!("GtkRcStyle @ {:?}", self as *const _))
.field("parent_instance", &self.parent_instance)
.field("name", &self.name)
.field("bg_pixmap_name", &self.bg_pixmap_name)
.field("font_desc", &self.font_desc)
.field("color_flags", &self.color_flags)
.field("fg", &self.fg)
.field("bg", &self.bg)
.field("text", &self.text)
.field("base", &self.base)
.field("xthickness", &self.xthickness)
.field("ythickness", &self.ythickness)
.field("rc_properties", &self.rc_properties)
.field("rc_style_lists", &self.rc_style_lists)
.field("icon_factories", &self.icon_factories)
.field("_truncated_record_marker", &"c_void")
.finish()
}
}There was a problem hiding this comment.
I want all fields to be there. So better having a useless "c_void" string than nothing from my point of view.
|
@sdroege, is good for you now? |
| w, | ||
| &klass.c_type, | ||
| &format!("write!(f, \"{name} @ {{:?}}\", self as *const _)", | ||
| name=klass.c_type) |
There was a problem hiding this comment.
You could use debug_tuple(name).field(the_pointer_string).build() here
| w, | ||
| &interface.c_type, | ||
| &format!("write!(f, \"{name} @ {{:?}}\", self as *const _)", | ||
| name=interface.c_type) |
| w, | ||
| &record.c_type, | ||
| &format!("write!(f, \"{name} @ {{:?}}\", self as *const _)", | ||
| name=record.c_type) |
|
Feel free to ignore that comment, it's all good to go for me. |
|
I'll let you handle the merging @EPashkin. |
|
Sorry but I want to quickly move towards the next release so I'll merge this and make a PR for the sys repository. |
|
Thanks, @GuillaumeGomez |
Fixes #486.
cc @EPashkin @sdroege