diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-07-02 17:24:21 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-07-02 17:24:21 +0100 |
| commit | 152c1dc711f472d3ae441a94aefd7a8b54811ffb (patch) | |
| tree | a00bfef908ff493324511243a68204e823b0293a /src/main/java/org/zwobble | |
| parent | 6d87397a04e0cd35a5560b50de37c3a3ed550af0 (diff) | |
Support empty inherent impl in Rust AST
Diffstat (limited to 'src/main/java/org/zwobble')
3 files changed, 45 insertions, 1 deletions
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriter.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriter.java index 59b792c..7ab09c7 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriter.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriter.java @@ -62,6 +62,10 @@ public class RustWriter implements AutoCloseable { writeEnum(enum_); } + case RustInherentImpl inherentImpl -> { + writeInherentImpl(inherentImpl); + } + case RustStructStruct structStruct -> { writeStructStruct(structStruct); } @@ -107,6 +111,14 @@ public class RustWriter implements AutoCloseable { this.writer.write("}"); } + private void writeInherentImpl(RustInherentImpl inherentImpl) throws IOException { + this.writer.write("impl "); + this.writeType(inherentImpl.type()); + this.writer.write(" {"); + this.writer.newLine(); + this.writer.write("}"); + } + private void writeStructStruct(RustStructStruct structStruct) throws IOException { this.writeDocComment(structStruct.docComment()); this.writer.write("pub struct "); diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustInherentImpl.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustInherentImpl.java new file mode 100644 index 0000000..55447bb --- /dev/null +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustInherentImpl.java @@ -0,0 +1,32 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.rust.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustInherentImpl imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustInherentImpl imports + +public record RustInherentImpl(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustType type) implements org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustItem { + public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustInherentImpl.Builder arbitrary() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustInherentImpl.Builder(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypePath.arbitrary().build()); + } + + public record Builder(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustType type) implements org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustItem.Builder { + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustInherentImpl build() { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustInherentImpl(type); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustInherentImpl.Builder withType(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustType type) { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustInherentImpl.Builder(type); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustInherentImpl.Builder withType(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustType.Builder type) { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustInherentImpl.Builder(type.build()); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustInherentImpl.Builder body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustInherentImpl.Builder body + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustInherentImpl body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustInherentImpl body +} diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustItem.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustItem.java index 4471b49..5da65a1 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustItem.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustItem.java @@ -5,7 +5,7 @@ package org.zwobble.hobgoblin.compiler.output.lang.rust.ast; // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustItem imports // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustItem imports -public sealed interface RustItem permits org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustEnum, org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustStructStruct { +public sealed interface RustItem permits org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustEnum, org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustInherentImpl, org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustStructStruct { public interface Builder { public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustItem build(); |
