[Rust] Improve Object API codegen: idiomatic types, Eq/Hash derives, String shadowing fix#8931
[Rust] Improve Object API codegen: idiomatic types, Eq/Hash derives, String shadowing fix#8931pittengermdp wants to merge 3 commits intogoogle:masterfrom
Conversation
…String shadowing fix
- Use short type names (String, Vec, Box) instead of fully-qualified
alloc:: paths in generated Object API code. Add corresponding
`use alloc::{vec::Vec, string::String, boxed::Box, string::ToString}`
imports to maintain no_std compatibility.
- Derive Eq and Hash on Object API types (tables, structs, unions,
bitflags) when the type hierarchy contains no floating-point fields.
Types with f32/f64 fields continue to derive only PartialEq.
- Fix String type shadowing: when a schema defines a table named
"String" in the same namespace, generated code now emits
std::string::String for standard library string fields, preventing
compilation failures. Wires up the existing but unused
NamespaceShadowsString/ObjectStringType helpers.
- Add #[allow(unused_imports)] to generated use/crate imports to
suppress warnings when not all imported names are used.
- Fix serde Deserialize impl for enums to use fully-qualified
std::string::String to avoid shadowing conflicts.
Regenerated all test files via scripts/generate_code.py.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
… is enabled The ObjectDerives() function was adding Eq/Hash but missing serde::Serialize/Deserialize when the --rust-serialize flag was active. This caused regenerated code to lose serde derives on *T types.
|
The use of fully qualified names for Vec, String, etc, was done intentionally in #8564. The point is to deal with the situation you cover in bullet 3. If you were to name a struct / table This can't be done for |
Summary
String,Vec,Box) instead of fully-qualifiedalloc::paths in generated Rust Object API code, withuse alloc::*imports added forno_stdcompatibilityEqandHashon Object API types (tables, structs, unions, bitflags) when no floating-point fields are present in the type hierarchyStringtype shadowing: when a schema defines a table namedString, generated code now emitsstd::string::Stringfor stdlib string fields (wires up existing unusedNamespaceShadowsString/ObjectStringTypehelpers)#[allow(unused_imports)]to suppress warnings on generated importsDeserializeimpl for enums to use fully-qualifiedstd::string::StringTest plan
flattests)