You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: add guideline to avoid Rust keywords as field names
Added explicit rules to both CLAUDE.md and CONTRIBUTING.md prohibiting the use of Rust keywords (type, use, trait, impl, etc.) as struct field names, especially in public APIs.
Problem: Rust keywords require the r# prefix (e.g., r#type), which causes serialization inconsistencies across language bindings:
- Polkadot.js converts to r_type or rType
- Serde serializes as type
- Creates confusion and breaks API consistency
Solution: Use alternative names like kind, variant, scope, category, or mode instead. This guideline applies to all public structs, especially those in api crates and types exposed to external clients.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+5Lines changed: 5 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -67,6 +67,11 @@ Be idiomatic. Use `Iterator`s, `Result`s, etc. PLEASE. Take a look at [Rust's AP
67
67
- the WASM runtime that Substrate runs on cannot unwind, so panics in functions like `on_initialize` will halt the chain (been there - more than once);
68
68
- use `Option` and `Result` types properly for error handling. NEVER allow `unused_must_use`. NEVER;
69
69
- always prefer panic-free functions and treat all potential errors (`checked_div` in favor of `/`, etc.).
70
+
-**Avoid Rust keywords as field names:**
71
+
- Never use Rust keywords (`type`, `use`, `trait`, `impl`, etc.) as struct field names, especially in public APIs;
72
+
- keywords require the `r#` prefix in Rust (e.g., `r#type`), which causes serialization inconsistencies across language bindings;
73
+
- Polkadot.js may convert `r#type` to `r_type` or `rType`, while Serde serializes it as `type`, creating confusion;
74
+
- use alternative names like `kind`, `variant`, `scope`, `category`, or `mode` instead.
0 commit comments