chaokunyang opened a new issue, #3417:
URL: https://github.com/apache/fory/issues/3417
### Feature Request
Add an explicit lifecycle guard in Fory Rust to forbid type registrations
after the resolver snapshot is initialized.
### Is your feature request related to a problem? Please describe
Yes. In Rust, `Fory` caches a finalized type resolver in `OnceLock`
(`final_type_resolver`).
After the first `serialize`/`deserialize` call, that snapshot is fixed. If
users call `register*` methods later, those new registrations do not affect the
already-initialized resolver snapshot, which can lead to confusing behavior
(types appear registered but runtime still fails to resolve them).
This creates a lifecycle footgun because registration order silently changes
behavior.
### Describe the solution you'd like
Forbid late registration with an explicit error.
Specifically:
- In all registration entry points (`register`, `register_union`,
`register_by_namespace`, `register_by_name`, `register_serializer*`,
`register_generic_trait`), detect whether `final_type_resolver` has already
been initialized.
- If initialized, return a clear error (for example `Error::not_allowed`)
explaining that registrations must be completed before first
serialization/deserialization.
- Keep behavior deterministic and fail-fast instead of silently ignoring
post-initialization registrations.
### Describe alternatives you've considered
- Rebuild the final resolver whenever new registrations are added after
initialization.
- This is more complex, risks performance regressions, and can introduce
thread-safety/lifecycle complexity.
- Keep current behavior and document it only.
- This still leaves a sharp edge and does not protect users from
accidental misuse.
### Additional context
Relevant code path is in Rust `fory-core` where `Fory` uses
`OnceLock<Result<TypeResolver, Error>>` for `final_type_resolver` and
registration APIs mutate `type_resolver`.
A fail-fast guard would make lifecycle semantics explicit and safer for
production usage.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]