Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork86
WIP: Convert Partial API to ownership-based pattern#970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Conversation
This commit migrates Partial methods from taking `&mut self` and returning`Result<&mut Self, ReflectError>` to taking `self` (ownership) and returning`Result<Self, ReflectError>`.Benefits:- Simpler error handling - no poisoning logic needed- Cleaner semantics - ownership transfer makes state transitions explicit- No invalid states - can't accidentally use a Partial after an error- Rust-idiomatic - follows builder pattern conventionsChanges:- All Partial methods now take `self` instead of `&mut self`- TypedPartial updated to match the ownership API- Removed poisoning logic (require_active, poison_and_cleanup, BuildFailed)- Fuzzer updated to use Option<Partial> pattern for error handlingStill TODO:- Update all deserializers (facet-json, facet-yaml, facet-toml, etc.)- Update facet-value deserialize.rs- Update all testsSee OWNERSHIP_API_MIGRATION.md for migration patterns.
- Convert all deserializers to use the new ownership API pattern- Replace &mut self methods with self -> Result<Self, Error>- Capture path/shape before ownership-taking calls for error handling- Use match blocks instead of map_err closures to avoid borrow-after-move- Update HeapValue::materialize for final type conversion
| /// Deserialize a struct from a JSON object. | ||
| fndeserialize_struct(&mutself,wip:&mutPartial<'input>) ->Result<()>{ | ||
| fndeserialize_struct(&mutself,mutwip:Partial<'input>) ->Result<Partial<'input>>{ |
Check warning
Code scanning / clippy
variable does not need to be mutable Warning
| log::trace!( | ||
| "deserialize_struct_with_flatten: {}", | ||
| wip.shape().type_identifier | ||
| wip = wip.shape().type_identifier |
Check warning
Code scanning / clippy
named argument wip is not used by name Warning
| message:format!( | ||
| "cannot deserialize into reference type '{}' - references require borrowing from existing data", | ||
| wip.shape().type_identifier | ||
| wip = wip.shape().type_identifier |
Check warning
Code scanning / clippy
named argument wip is not used by name Warning
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
With the ownership-based Partial API, these tests are no longer needed:- double_free_test.rs: Double-free is impossible by construction- dynamic_value_segv_test.rs: Uses old inner_mut() API- leak_repro.rs: Uses old inner_mut() APIThe type system now enforces proper ownership, making these failuremodes impossible. The fuzzer can still catch any remaining issues.Updated map_leak_test.rs for the ownership API pattern.
- Remove TypedPartial wrapper, Partial::alloc::<T>() now returns Partial directly- Update tests to use .materialize::<T>()? instead of HeapValue dereference- Fix .unwrap_err() calls that require Debug on Partial (use match instead)- Remove obsolete map_leak_test.rs which tested invalid begin_inner() operation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
clippy found more than 20 potential problems in the proposed changes. Check theFiles changed tab for more details.
Summary
This PR migrates the
PartialAPI from a mutable reference pattern (&mut self) to an ownership-based pattern (self).Changes
selfinstead of&mut selfand returnResult<Self, ReflectError>instead ofResult<&mut Self, ReflectError>Dropwhen errors consume thePartialOption<Partial>pattern for handling operations that may failBenefits
Still TODO
Migration Pattern
See
facet-reflect/OWNERSHIP_API_MIGRATION.mdfor complete migration guide.Test plan