Skip to content

Add read-only field aliases (rfl::Alias) - #83

Open
clockblocker wants to merge 4 commits into
mainfrom
field-alias
Open

clockblocker wants to merge 4 commits into
mainfrom
field-alias

Conversation

@clockblocker

Copy link
Copy Markdown
Owner

Summary

Adds rfl::Alias<"old_name", T> for declaring one or more read-only alternate wire names on a struct field while always serializing and emitting schemas under the canonical primary wire name.

Motivated by real-world config/protocol evolution (e.g. transmission's rpc-whitelist / peer-port / deprecated settings migration where legacy snake_case/kebab-case keys must still be accepted on load and CLI without emitting duplicate keys on save).

What Changed

  • rfl::Alias<StringLiteral _name, T> (include/rfl/Alias.hpp): Matches rfl::Rename / rfl::Description / rfl::Short ergonomics (.value(), .get(), *, ->, (), constrained default ctor, implicit conversion, ==, <=>, std::hash). Nesting rfl::Alias<"a", rfl::Alias<"b", T>> collects all aliases.
  • Wrapper transparency (field_aliases.hpp, is_alias.hpp, ParserAlias.hpp): Composes cleanly with Rename, Description, Deprecated, DefaultVal, Short, Positional, std::optional, Skip, Attribute, Commented, and case-transforming naming processors (SnakeCaseToCamelCase, SnakeCaseToKebabCase, SnakeCaseToPascalCase, CamelCaseToSnakeCase, ToAllCaps).
  • Read / Write / Schema semantics:
    • Write and to_schema always emit only the canonical primary wire name (preserving inner Description/Deprecated/DefaultVal/Validator metadata).
    • ViewReader and ViewReaderWithDefault accept the primary name or any declared alias, honor rfl::NoExtraFields (aliases do not leak into rfl::ExtraFields), and return an error if both the primary name and an alias (or two aliases) are supplied for the same field. Zero overhead for fields without aliases.
    • Compile-time static_assert(internal::no_alias_collisions<...>()) rejects cross-field alias collisions (after naming processors run).
  • CLI & Env support: rfl::cli::internal::Options and resolve_args accept --<alias> flags with conflict detection against primary names, other aliases, Short, and Positional; rfl::env::Reader probes field aliases.
  • Docs & tests: Added docs/content/alias.md (+ index & CLI docs), tests/json/test_alias.cpp, tests/yaml/test_alias.cpp, tests/generic/test_alias.cpp, tests/cli/test_alias.cpp, and 2 compile-fail collision tests.

Verification

  • Full CTest suite (JSON, YAML, Generic + 2 compile-fail targets, CLI, Env) built with -Wall -Werror: 665/665 tests passed (100%).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant