Skip to content

[Rust] Derive more traits#4142

Merged
wing328 merged 1 commit intoOpenAPITools:masterfrom
borsboom:rust-derive-more-traits
Nov 19, 2019
Merged

[Rust] Derive more traits#4142
wing328 merged 1 commit intoOpenAPITools:masterfrom
borsboom:rust-derive-more-traits

Conversation

@borsboom
Copy link
Copy Markdown
Contributor

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\. If contributing template-only or documentation-only changes which will change sample output, be sure to build the project first.
  • Filed the PR against the correct branch: master, 4.1.x, 5.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

This adds some common standard traits to the generated models:

  • For structs and complex enums, adds Clone.
  • For simple enums, adds Clone, Copy, Eq, Ord, PartialOrd, Hash.

These end up coming in really handy for client code.

/cc @frol @farcaller @bjgill @richardwhiuk

* Simple enums: add: Clone, Copy, Eq, Ord, PartialOrd, Hash
* Structs and complex enums: add `Clone`
@bjgill
Copy link
Copy Markdown
Contributor

bjgill commented Oct 15, 2019

I've not looked closely, but does this work when the enum contains f64 or similar that doesn't work with Ord or Eq?

@borsboom
Copy link
Copy Markdown
Contributor Author

I don't believe the "simple" enums that get these traits will ever contain other types. The enum values are generated as

#[serde(rename = "{{{value}}}")]
{{name}},

so these are just a simple list of names that don't contain anything else.

@bcourtine
Copy link
Copy Markdown
Contributor

I agree that having "Cloneable" models can be usefull.

I often add the derivation after generating client code.

@wing328
Copy link
Copy Markdown
Member

wing328 commented Oct 25, 2019

CircleCI failure not related to this PR.

@wing328
Copy link
Copy Markdown
Member

wing328 commented Nov 19, 2019

@borsboom Looks like there's no further feedback. Thanks for the PR.

@wing328 wing328 merged commit 6e2e542 into OpenAPITools:master Nov 19, 2019
@wing328 wing328 added this to the 4.2.2 milestone Nov 19, 2019
@wing328
Copy link
Copy Markdown
Member

wing328 commented Dec 2, 2019

@Snazzie
Copy link
Copy Markdown

Snazzie commented Apr 18, 2024

Eq and Hash doesnt get generated anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants