Skip to content

Commit

Permalink
Add const to generated enum values()
Browse files Browse the repository at this point in the history
Enum values() functions return static arrays of static strings and could
be of compile time use. Make callable in const contexts.
  • Loading branch information
lsr0 committed Nov 20, 2022
1 parent 5eeb5d7 commit a5f775a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -478,3 +478,9 @@ x-amzn-errortype: com.example.service#InvalidRequestException
references = ["smithy-rs#1982"]
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "server" }
author = "david-perez"

[[smithy-rs]]
message = "Make generated enum `values()` functions callable in const contexts."
references = []
meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client" }
author = "lsr0"
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ open class EnumGenerator(
}

docs("Returns all the `&str` representations of the enum members.")
rustBlock("pub fn $Values() -> &'static [&'static str]") {
rustBlock("pub const fn $Values() -> &'static [&'static str]") {
withBlock("&[", "]") {
val memberList = sortedMembers.joinToString(", ") { it.value.dq() }
rust(memberList)
Expand Down Expand Up @@ -198,7 +198,7 @@ open class EnumGenerator(
}

rust("/// Returns all the `&str` values of the enum members.")
rustBlock("pub fn $Values() -> &'static [&'static str]") {
rustBlock("pub const fn $Values() -> &'static [&'static str]") {
withBlock("&[", "]") {
val memberList = sortedMembers.joinToString(", ") { it.value.doubleQuote() }
write(memberList)
Expand Down

0 comments on commit a5f775a

Please sign in to comment.