Factor out ptr/reference target type write
diff --git a/gen/src/write.rs b/gen/src/write.rs
index 930ce0b..d3052ba 100644
--- a/gen/src/write.rs
+++ b/gen/src/write.rs
@@ -1173,31 +1173,11 @@
write!(out, ">");
}
Type::Ref(r) => {
- if let Type::Ptr(_) = r.inner {
- write_type_space(out, &r.inner);
- if !r.mutable {
- write!(out, "const");
- }
- } else {
- if !r.mutable {
- write!(out, "const ");
- }
- write_type(out, &r.inner);
- }
+ write_pointee_type(out, &r.inner, r.mutable);
write!(out, " &");
}
Type::Ptr(p) => {
- if let Type::Ptr(_) = p.inner {
- write_type_space(out, &p.inner);
- if !p.mutable {
- write!(out, "const");
- }
- } else {
- if !p.mutable {
- write!(out, "const ");
- }
- write_type(out, &p.inner);
- }
+ write_pointee_type(out, &p.inner, p.mutable);
write!(out, " *");
}
Type::Str(_) => {
@@ -1235,6 +1215,21 @@
}
}
+// Write just the T type behind a &T or &mut T or *const T or *mut T.
+fn write_pointee_type(out: &mut OutFile, inner: &Type, mutable: bool) {
+ if let Type::Ptr(_) = inner {
+ write_type_space(out, inner);
+ if !mutable {
+ write!(out, "const");
+ }
+ } else {
+ if !mutable {
+ write!(out, "const ");
+ }
+ write_type(out, inner);
+ }
+}
+
fn write_atom(out: &mut OutFile, atom: Atom) {
match atom {
Bool => write!(out, "bool"),