Skip to content

feat(rust): support external-type serialization - #3881

Merged
chaokunyang merged 11 commits into
apache:mainfrom
chaokunyang:support_rust_external_type_serialization
Jul 26, 2026
Merged

feat(rust): support external-type serialization#3881
chaokunyang merged 11 commits into
apache:mainfrom
chaokunyang:support_rust_external_type_serialization

Conversation

@chaokunyang

@chaokunyang chaokunyang commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator

Why?

Rust's orphan rule prevents applications from implementing Fory traits directly for types owned by other crates. Users currently need local wrapper or mirror types for common external types such as uuid and jiff, which adds conversions and makes external types difficult to use in fields, containers, roots, and dynamic values.

What does this PR do?

  • Introduces target-based external-type serialization for Rust. ForyStruct, ForyEnum, and ForyUnion can derive serializers for types owned by another crate, while manual serializers can provide customized encodings.
  • Adds serialize_with, serialize_to_with, deserialize_with, and deserialize_from_with for serializer-selected roots.
  • Supports node-local serializer selection for direct fields and recursive list, map, and tuple children.
  • Adds allocation-free carrier serializers for the supported Rust wrappers, collections, maps, fixed arrays, and tuple arities 1 through 22, so external serializers compose recursively without registration or runtime provider trees.
  • Unifies ordinary, external, manual, carrier, Any, and application-trait serialization on one serializer/codec ownership model while preserving existing wire encodings, schema metadata, reference tracking, compatible mode, and graph-memory checks.
  • Updates Rust code generation, public exports, API fixtures, focused tests, the Rust xlang suite, guides/specifications, and separates local/external Rust benchmarks from the xlang benchmark package.

Related issues

Closes #3873

#1226
#2671

AI Contribution Checklist

  • Substantial AI assistance was used in this PR: yes / no
  • If yes, I included a completed AI Contribution Checklist in this PR description and the required AI Usage Disclosure.
  • If yes, my PR description includes the required ai_review summary and screenshot evidence or equivalent persisted links of the final clean AI review results from both fresh reviewers described in AI_POLICY.md, the Fory-guided reviewer and the independent general reviewer, on the current PR diff or current HEAD after the latest code changes.

Does this PR introduce any user-facing change?

Yes. Rust users can define structural or manual serializers for third-party types, select them at roots or nested field nodes, and compose them through Fory-provided carrier serializers.

  • Does this PR introduce any public API change?
  • Does this PR introduce any binary protocol compatibility change?

Benchmark

Adjacent Criterion comparisons against apache/main:

  • Ordinary sample/fory_serialize: retained median delta -0.158%.
  • Ordinary sample/fory_deserialize: 211.69 ns -> 213.71 ns (+0.954%).
  • External structural root: self-owned 21.993 ns, selected 20.984 ns (selected 4.59% faster).
  • External recursive field: self-owned 53.675 ns, selected 53.320 ns (selected 0.66% faster).

All affected retained medians remain within the 1% regression gate; the selected paths preserve equivalent wire work and add no hot-path allocation.

@chaokunyang
chaokunyang merged commit df991ac into apache:main Jul 26, 2026
71 checks passed
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.

[Rust] How to support most commonly used Rust crate types?

2 participants