mirror of
https://github.com/roc-lang/roc.git
synced 2024-11-10 18:08:55 +03:00
Bindgen Debug impl for tag unions
This commit is contained in:
parent
a74c7c3009
commit
749e4b25c7
@ -503,6 +503,53 @@ fn write_tag_union(
|
||||
writeln!(buf, "impl Copy for {} {{}}\n", name)?;
|
||||
}
|
||||
|
||||
// The Debug impl for the tag union
|
||||
{
|
||||
write!(
|
||||
buf,
|
||||
indoc!(
|
||||
r#"
|
||||
impl core::fmt::Debug for {} {{
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {{
|
||||
f.write_str("{}::")?;
|
||||
|
||||
unsafe {{
|
||||
match self.tag {{
|
||||
"#
|
||||
),
|
||||
name, name
|
||||
)?;
|
||||
|
||||
write_impl_tags(
|
||||
4,
|
||||
tags.iter(),
|
||||
&discriminant_name,
|
||||
buf,
|
||||
|tag_name, opt_payload_id| {
|
||||
if opt_payload_id.is_some() {
|
||||
format!(
|
||||
r#"f.debug_tuple("{}").field(&self.variant.{}).finish(),"#,
|
||||
tag_name, tag_name
|
||||
)
|
||||
} else {
|
||||
format!(r#"f.write_str("{}"),"#, tag_name)
|
||||
}
|
||||
},
|
||||
)?;
|
||||
|
||||
writeln!(
|
||||
buf,
|
||||
indoc!(
|
||||
r#"
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
"#
|
||||
),
|
||||
)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -348,6 +348,21 @@ fn tag_union_aliased() {
|
||||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for MyTagUnion {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
f.write_str("MyTagUnion::")?;
|
||||
|
||||
unsafe {
|
||||
match self.tag {
|
||||
tag_MyTagUnion::Bar => f.debug_tuple("Bar").field(&self.variant.Bar).finish(),
|
||||
tag_MyTagUnion::Baz => f.write_str("Baz"),
|
||||
tag_MyTagUnion::Blah => f.debug_tuple("Blah").field(&self.variant.Blah).finish(),
|
||||
tag_MyTagUnion::Foo => f.debug_tuple("Foo").field(&self.variant.Foo).finish(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
"#
|
||||
)
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user