fix(utoipa-gen): remove unnecessary allocation with to_string in expanded code #982
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Taking something that is a string and converting it to a string usingto_string()
kind of misses the point of why we are doing the conversion in the first place, and also fails to document this to the reader.to_owned()
fully captures the reason that a conversion is required at a particular spot: borrowed (&str
) to owned (String
).Some people enable this clippy lint in order to enforce this style:- https://rust-lang.github.io/rust-clippy/master/index.html#/str_to_stringCode generated by utoipa macro is triggering this lint. To avoid that, this patch is replacing theto_string()
usages in generated code byto_owned()
.This patch is not changing any otherto_string()
because the utoipa project itself does not need to adhere to this style. The goal is just to reduce friction for downstream consumers.Here is how it shows up without this fix:
There is no lint for the opposite ("useto_string()
instead ofto_owned()
), so it seems safe to apply this fix.