Conversation
This follows the existing conventions. (e.g. `catalyst: add exclude_field_attributes`, `catalyst: handle private fields`). The change adds an `unsafe` feature gate that switches `Complex::decouple` between safe destructuring and `ManuallyDrop` + `ptr::read`, with the feature forwarded from `struct-patch` and the complex-example crate.
…ack` under `unsafe` feature
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.
Add
unsafefeature for zero-memory-move catalyst operationsThis PR introduces an optional
unsafefeature that usesManuallyDrop+ptr::read/MaybeUninit+ptr::writeto avoid memory moves in the generated catalyst and substrate code.Changes
derive/src/catalyst.rsComplex::decouple— gated into two implementations:unsafe: wrapsselfinManuallyDrop, reads fields viaptr::readto construct the catalyst and substrate without movingCatalyst::bind— gated into two implementations:unsafe: wrapsselfinManuallyDrop, reads catalyst fields viaptr::read(substrate still uses__substrate_unpack()since those fields are private cross-crate)to_ptr_read_stream/to_ptr_read_arg_streamparameterized with a sourceIdentderive/src/substrate.rs__substrate_new— gated into two implementations:unsafe: usesMaybeUninit+ptr::write+addr_of_mutto construct the struct field-by-field__substrate_unpack— gated into two implementations:unsafe: usesManuallyDrop+ptr::readto extract fields without runningDropFeature forwarding
derive/Cargo.toml: addedunsafe = []featurelib/Cargo.toml:unsafeforwards tostruct-patch-derive/unsafecomplex-example/catalyst/Cargo.toml:unsafeforwards tostruct-patch/unsafe, enablingcargo test -p catalyst --features unsafefor easy testingOther
flake.nix:check-catalystnow also runscargo test -p catalyst --features unsafeREADME.md: documented theunsafefeature; replaced the "future" note with the actual implementation0.12.7Testing
All 9 tests pass both with and without the
unsafefeature:cargo test -p substrate(3 tests)cargo test -p catalyst(3 tests, safe path)cargo test -p catalyst --features unsafe(3 tests, unsafe path)