Skip to content

Commit

Permalink
Refactor constrainedValueTypeIsNotFinalType to make it a bit more r…
Browse files Browse the repository at this point in the history
…eadable
  • Loading branch information
Fahad Zubair committed Oct 29, 2024
1 parent 11a20b5 commit 6362a0d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,32 +153,31 @@ class UnconstrainedCollectionGenerator(

val finalType =
if (constrainedValueTypeIsNotFinalType) {
constrainedShapeSymbolProvider.toSymbol(shape.member)
symbolProvider.toSymbol(shape.member)
} else {
constrainedMemberSymbol
}

val constrainValueWritable =
writable {
conditionalBlock("inner.map(|inner| ", ").transpose()", constrainedMemberSymbol.isOptional()) {
rustTemplate(
"""
inner.try_into()
#{FinalMapping}
.map_err(|inner_violation| (idx, inner_violation))
""",
"FinalMapping" to
writable {
if (constrainedValueTypeIsNotFinalType) {
rustTemplate(
".map(|c : #{ConstrainedMemberSymbol}| c.into())",
"ConstrainedMemberSymbol" to constrainedMemberSymbol,
)
} else {
rust("")
}
},
)
if (constrainedValueTypeIsNotFinalType) {
rustTemplate(
"""
#{ConstrainedMemberSymbol}::try_from(inner)
.map(|inner_constrained| inner_constrained.into())
.map_err(|inner_violation| (idx, inner_violation))
""",
"ConstrainedMemberSymbol" to constrainedMemberSymbol,
)
} else {
rustTemplate(
"""
inner.try_into()
.map_err(|inner_violation| (idx, inner_violation))
""",
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ class ConstraintsTest {
primitiveBoolean.isDirectlyConstrained(symbolProvider) shouldBe false
}

// TODO(#3895): Move tests that use `generateAndCompileServer` into `constraints.smithy` once issue is resolved
private fun generateAndCompileServer(
model: Model,
pubConstraints: Boolean = true,
Expand Down

0 comments on commit 6362a0d

Please sign in to comment.