Unverified Commit 0f26eade authored by Lindsay Roberts's avatar Lindsay Roberts Committed by GitHub
Browse files

Add const to generated enum values() (#2011)



* Add const to generated enum values()

Enum values() functions return static arrays of static strings and could
be of compile time use. Make callable in const contexts.

* Add reference to PR in changelog next for const enum values()

* Correct changelog next target to all for const enum values()

Co-authored-by: default avatarLuca Palmieri <20745048+LukeMathWalker@users.noreply.github.com>
parent 86fd8f59
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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 = ["smithy-rs#2011"]
meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "all" }
author = "lsr0"
+2 −2
Original line number Diff line number Diff line
@@ -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)
@@ -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)