Implement DerefMut for Once fixtures, to allow mutable access to non-Clone fixture resources#55
Merged
mgautierfr merged 2 commits intoApr 29, 2026
Conversation
… a fixture as 'mut' without having to clone.
mgautierfr
requested changes
Mar 4, 2026
Owner
mgautierfr
left a comment
There was a problem hiding this comment.
This is nice. Thanks for the PR.
Maybe few improvement of the tests but else I agree with the feature.
Can you also update the documentation (in rustest/src/lib.rs and Readme) ?
Contributor
Author
|
Will update docs also |
9c91fa7 to
ec66c34
Compare
Contributor
Author
|
Sorry, not sure what status report is awaited... |
Owner
Sorry, I have somehow missed that you update the PR and forget about it. |
mgautierfr
approved these changes
Apr 29, 2026
Owner
For some reason, github has not triggered a workflow run on your second commit and so never see the status reported. The change of the second commit is small enough to merge without the CI passing. Thanks for the PR. |
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.
Typically, if a test needs mutable access to a fixture, the test can clone the fixture value and rebind it as mutable:
This is necessary when rustest is used in an embedded application, where access to hardware may require mutable access to a resource held by the fixture (e.g. an I2C bus).
Unfortunately, mostly due to HAL restrictions, sometimes a fixture isn't trivially
Clone, so this is not possible without additional interior mutability wrappers around the resources. This is significant additional complexity just to provide test ability.This PR introduces a simple implementation of
DerefMutforOncefixtures, avoiding a.clone()and allowing this:It might make some sense for shared or global fixtures to be
DerefMuttoo, but the solution is more complex, and will involve locking. So onlyOncefixtures have this trait implemented by the#[fixture]macro in this PR.