[Rust] Replace more HeaderValue::from_str with compile time from_static#21689
Conversation
There was a problem hiding this comment.
Pull Request Overview
This pull request replaces more instances of HeaderValue::from_str with HeaderValue::from_static for compile-time string values in Rust-generated code. This optimization removes unnecessary runtime string validation since the header values are known at compile time.
- Replaces
HeaderValue::from_str()withHeaderValue::from_static()for static header values - Updates Mustache templates to generate more efficient code
- Includes minor import ordering improvements for consistency
Reviewed Changes
Copilot reviewed 53 out of 53 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| samples/server/petstore/rust-server/output/*/src/server/mod.rs | Replace HeaderValue::from_str() calls with static variants for Content-Type headers |
| samples/server/petstore/rust-server/output/*/src/client/mod.rs | Replace dynamic header creation with static variants for known media types |
| samples/server/petstore/rust-axum/output/*/src/server/mod.rs | Replace HeaderValue::from_str() with static variants in Axum implementations |
| samples/server/petstore/rust-axum/output/*/src/types.rs | Minor import ordering improvements for consistency |
| modules/openapi-generator/src/main/resources/rust-server/*.mustache | Update Mustache templates to generate static header values |
|
Thanks for submitting this. You've not mentioned why you've removed the error context on some of the responses. Could you explain that decision. |
Sure, error handling was there, because |
|
the change sounds reasonable to me let's give it a try |
This pull requests replace more instances of
HeaderValue::from_strwithHeaderValue::from_static.@frol @farcaller @richardwhiuk @paladinzh @jacob-pro @dsteeley
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)