feat(rust): support external-type serialization - #3881
Merged
chaokunyang merged 11 commits intoJul 26, 2026
Merged
Conversation
urlyy
approved these changes
Jul 26, 2026
urlyy
approved these changes
Jul 26, 2026
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.
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
uuidandjiff, which adds conversions and makes external types difficult to use in fields, containers, roots, and dynamic values.What does this PR do?
ForyStruct,ForyEnum, andForyUnioncan derive serializers for types owned by another crate, while manual serializers can provide customized encodings.serialize_with,serialize_to_with,deserialize_with, anddeserialize_from_withfor serializer-selected roots.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.Related issues
Closes #3873
#1226
#2671
AI Contribution Checklist
yes/noyes, I included a completed AI Contribution Checklist in this PR description and the requiredAI Usage Disclosure.yes, my PR description includes the requiredai_reviewsummary and screenshot evidence or equivalent persisted links of the final clean AI review results from both fresh reviewers described inAI_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.
Benchmark
Adjacent Criterion comparisons against
apache/main:sample/fory_serialize: retained median delta-0.158%.sample/fory_deserialize:211.69 ns->213.71 ns(+0.954%).21.993 ns, selected20.984 ns(selected4.59%faster).53.675 ns, selected53.320 ns(selected0.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.