Skip to content

Prototype: WpDeriveParsedValue proc macro generating {Enum}Value wrapper#1367

Draft
oguzkocer wants to merge 5 commits into
trunkfrom
prototype/parsed-value-proc-macro
Draft

Prototype: WpDeriveParsedValue proc macro generating {Enum}Value wrapper#1367
oguzkocer wants to merge 5 commits into
trunkfrom
prototype/parsed-value-proc-macro

Conversation

@oguzkocer

@oguzkocer oguzkocer commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Description

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.

Changelog

  • I've added an entry to CHANGELOG.md under ## [Unreleased], using the Keep a Changelog categories (Added, Changed, Deprecated, Removed, Fixed, Security). Prefix breaking changes with **BREAKING:**.

oguzkocer added 2 commits May 31, 2026 13:41
…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.
@oguzkocer oguzkocer added the Rust label Jun 1, 2026
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).
@wpmobilebot

wpmobilebot commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

XCFramework Build

This PR's XCFramework is available for testing. Add to your Package.swift:

.package(url: "https://github.com/automattic/wordpress-rs", branch: "pr-build/1367")

Built from 92a67e5

oguzkocer added 2 commits June 4, 2026 00:28
- `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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants