Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding impl Display for enum #3391

Merged
merged 1 commit into from
Feb 7, 2024

Conversation

iampkmone
Copy link
Contributor

Motivation and Context

This change address the #3335

Description

Added Display trait to the Enum.

Testing

Updated the ClientEnumGeneratorTest.kt which test the impl Display for the enums.

Checklist

  • I have updated CHANGELOG.next.toml if I made changes to the smithy-rs codegen or runtime crates

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@iampkmone iampkmone requested review from a team as code owners February 1, 2024 07:05
Copy link
Collaborator

@rcoh rcoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Some formatting and small suggestions

"""
impl #{Display} for $UnknownVariantValue {
fn fmt(&self, f: &mut #{Fmt}::Formatter) -> #{Fmt}::Result {
write!(f,"{}",self.0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
write!(f,"{}",self.0)
write!(f, "{}", self.0)

""",
)
}
rust(""" ${context.enumName}::Unknown(value) => write!(f,"{}",value) """)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rust(""" ${context.enumName}::Unknown(value) => write!(f,"{}",value) """)
rust("""${context.enumName}::Unknown(value) => write!(f,"{}",value)""")

@@ -28,3 +28,9 @@ message = "Add `try_into_http1x` and `try_from_http1x` to Request and Response c
references = ["aws-sdk-rust#977", "smithy-rs#3365", "smithy-rs#3373"]
meta = { "breaking" = false, "bug" = false, "tada" = false }
author = "rcoh"

[[smithy-rs]]
message = "Added impl Display trait to Enum."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
message = "Added impl Display trait to Enum."
message = "Added impl `Display` to Enums."

@@ -28,3 +28,9 @@ message = "Add `try_into_http1x` and `try_from_http1x` to Request and Response c
references = ["aws-sdk-rust#977", "smithy-rs#3365", "smithy-rs#3373"]
meta = { "breaking" = false, "bug" = false, "tada" = false }
author = "rcoh"

[[smithy-rs]]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this also impacts the SDK, we should add a duplicate entry under aws-sdk-rust


[[smithy-rs]]
message = "Added impl Display trait to Enum."
references = ["smithy-rs#3336"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
references = ["smithy-rs#3336"]
references = ["smithy-rs#3336", "smithy-rs#3391"]

@@ -94,6 +94,8 @@ class ClientEnumGeneratorTest {
"""
assert_eq!(format!("{:?}", SomeEnum::Foo), "Foo");
assert_eq!(format!("{:?}", SomeEnum::Bar), "Bar");
assert_eq!(SomeEnum::Foo.to_string(), "Foo");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you have one of these go directly for format!("{}", value) instead of to_string for completeness?

@iampkmone iampkmone force-pushed the feature/display_trait_enum branch from 119b2cf to 85d40cc Compare February 6, 2024 20:06
"""
impl #{Display} for $UnknownVariantValue {
fn fmt(&self, f: &mut #{Fmt}::Formatter) -> #{Fmt}::Result {
write!(f, "{}", self.0)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed the formatting.

""",
)
}
rust("""${context.enumName}::Unknown(value) => write!(f,"{}",value)""")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed the formatting.

@iampkmone iampkmone force-pushed the feature/display_trait_enum branch from 85d40cc to e95d5d1 Compare February 6, 2024 20:12
Copy link
Collaborator

@rcoh rcoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@rcoh rcoh added this pull request to the merge queue Feb 7, 2024
Merged via the queue into smithy-lang:main with commit 4187b63 Feb 7, 2024
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants