Prototype: WpDeriveParsedValue proc macro generating {Enum}Value wrapper#1367
Draft
oguzkocer wants to merge 5 commits into
Draft
Prototype: WpDeriveParsedValue proc macro generating {Enum}Value wrapper#1367oguzkocer wants to merge 5 commits into
WpDeriveParsedValue proc macro generating {Enum}Value wrapper#1367oguzkocer wants to merge 5 commits into
Conversation
…wrapper Adds a derive macro that generates a `uniffi::Object` wrapper type for enums with fallback variants. Applied to `PostStatus` as proof of concept. Generated `PostStatusValue`: - `uniffi::Object` with controlled construction (no inconsistent state) - Constructors: `new_from_raw(String)`, `new_from_value(PostStatus)` - Accessors: `value() -> Option<PostStatus>`, `raw() -> String` - Comparison: `is_code()`, `is_raw()`, `is_any_code()` - Trait impls: `Display`, `FromStr`, `Serialize`, `Deserialize`, `Eq`, `Hash` - Equality normalizes through the raw string Supports both strum-based (default) and serde-based resolution via `#[parsed_value(resolution = "serde")]` attribute.
Library code compiles clean across the entire workspace: - `SparseAnyPost.status`: `Option<PostStatus>` → `Option<Arc<PostStatusValue>>` - `PostCreateParams.status`, `PostUpdateParams.status`: → `Option<Arc<PostStatusValue>>` - `MediaCreateParams.status`, `MediaUpdateParams.status`: → `Option<Arc<PostStatusValue>>` - `PostListParams.status`: kept as `Vec<PostStatus>` (orphan rule prevents `FromStr for Arc<T>` needed by the query parsing infra) Proc macro generates `AsQueryValue` and `OptionFromStr` impls for `Arc<PostStatusValue>` to integrate with the URL query infrastructure. All wp_mobile filter/service code updated to use `is_code()`/`is_raw()`. Test code not yet updated — only library targets compile.
Update all test files across the workspace: - `wp_mobile_cache` repo tests: use `is_code()` for status assertions - `wp_api_integration_tests`: update macros and direct usages to wrap `PostStatus` in `Arc<PostStatusValue>` for params, use `is_code()` for assertions - `wp_mobile_integration_tests`: same pattern Full workspace compiles clean with clippy (--all-targets --all-features).
Collaborator
XCFramework BuildThis PR's XCFramework is available for testing. Add to your .package(url: "https://github.com/automattic/wordpress-rs", branch: "pr-build/1367")Built from 92a67e5 |
- `value()` → `parsed()` — returns the parsed enum variant - `is_code()` → `matches()` — check against a known variant - `is_raw()` → `matches_raw()` — check against a raw string - `is_any_code()` → `matches_any()` — check against multiple variants
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Adds a derive macro that generates a
uniffi::Objectwrapper type for enums with fallback variants. Applied toPostStatusas proof of concept.Generated
PostStatusValue:uniffi::Objectwith controlled construction (no inconsistent state)new_from_raw(String),new_from_value(PostStatus)value() -> Option<PostStatus>,raw() -> Stringis_code(),is_raw(),is_any_code()Display,FromStr,Serialize,Deserialize,Eq,HashSupports both strum-based (default) and serde-based resolution via
#[parsed_value(resolution = "serde")]attribute.Changelog
CHANGELOG.mdunder## [Unreleased], using the Keep a Changelog categories (Added,Changed,Deprecated,Removed,Fixed,Security). Prefix breaking changes with**BREAKING:**.