8000 Make enums rust enums not strings by aj-bagwell · Pull Request #1867 · rusoto/rusoto · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Make enums rust enums not strings #1867

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

aj-bagwell
Copy link
@aj-bagwell aj-bagwell commented Nov 27, 2020

Possible fix to #340
This converts botocore shapes that are an enum into a rust enum.

Each enum has an UknownVariant variant that is used if the string that it is deserialised from is not a known variant.

This means that it can implment both From and Into and always round trip back to the same string.

This means that unsupported future varaints can be sent via a simple "FOO".into() and matched with

match foo {
    x if x.to_string() == "FOO" => ....
}

This require carefull attention as it would be a massive API change.

Edit 2021-02-25:

There are some ugly side effects of this. I had to add a default implementation to the enums so that input structs can derive default, I went with UknownVariant("") as that is what the original code would have done but I don't like it.

I also had to add a bunch of conversion impls for the enums which adds to the generated code size:

  • Display
  • Into<Sting>, From<String>
  • Into<&str>, From<&str> for a borrowed enum
  • ToParam
  • serde Serialize and Deserialize if needed/configured

@aj-bagwell aj-bagwell changed the title Enums possible fix to #340 Make enums rust enums not strings Nov 27, 2020
@luben
Copy link
Contributor
luben commented Feb 20, 2021

Any idea why the build/S3 test is failing?

@aj-bagwell
Copy link
Author

@luben I have rebased it on to master and fixed the tests, there was some places that needed string litterals replacing with the equivielant enum.

@dcormier
Copy link

What can be done to move this forward?

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.

4 participants
0