diff options
Diffstat (limited to 'src/main/java/org/zwobble')
| -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 |
