diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-08-09 16:56:52 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-08-09 16:56:52 +0100 |
| commit | 942ca80a1f6d1cded5cb112dd347f8301567fe3f (patch) | |
| tree | 401f109cadb436a27fd614b71000a46564a504fa /src/main | |
| parent | 9105526554dc825095c02fdafb1fb7d1852aa134 (diff) | |
Add bounds to type params in Rust AST
Diffstat (limited to 'src/main')
| -rw-r--r-- | src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriter.java | 9 | ||||
| -rw-r--r-- | src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypeParam.java | 30 |
2 files changed, 33 insertions, 6 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 7ae6bcf..72d17b7 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 @@ -283,6 +283,15 @@ public class RustWriter implements AutoCloseable { private void writeTypeParam(RustTypeParam typeParam) throws IOException { this.writeIdentifier(typeParam.name()); + + if (!typeParam.bounds().isEmpty()) { + this.writer.write(": "); + writeWithSeparator( + typeParam.bounds(), + this::writeType, + () -> this.writer.write(" + ") + ); + } } // === Associated items === diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypeParam.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypeParam.java index db689f4..f7ce00a 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypeParam.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypeParam.java @@ -6,25 +6,43 @@ package org.zwobble.hobgoblin.compiler.output.lang.rust.ast; // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeParam imports public record RustTypeParam( - org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIdentifier name + org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIdentifier name, + java.util.List<org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPath> bounds ) { public static org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeParam.Builder arbitrary() { - return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeParam.Builder(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIdentifier.arbitrary().build()); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeParam.Builder(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIdentifier.arbitrary().build(), java.util.List.of()); } public record Builder( - org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIdentifier name + org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIdentifier name, + java.util.List<org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPath> bounds ) { public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeParam build() { - return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeParam(name); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeParam(name, bounds); } public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeParam.Builder withName(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIdentifier name) { - return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeParam.Builder(name); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeParam.Builder(name, bounds); } public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeParam.Builder withName(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustIdentifier.Builder name) { - return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeParam.Builder(name.build()); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeParam.Builder(name.build(), bounds); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeParam.Builder withBounds(java.util.List<org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPath> bounds) { + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeParam.Builder(name, bounds); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeParam.Builder addBound(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPath bound) { + var bounds = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPath>(this.bounds); + bounds.add(bound); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeParam.Builder(name, bounds); + } + + public org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeParam.Builder addBound(org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPath.Builder bound) { + var bounds = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPath>(this.bounds); + bounds.add(bound.build()); + return new org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeParam.Builder(name, bounds); } // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypeParam.Builder body |
