Adds guarded ref and mut access for UnsafeCell #116
Closed
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.
This PR adds methods
guard_ref_access
andguard_mut_access
toUnsafeCell
as an alternative towith
andwith_mut
for tracking read and write access to the underlying cell data.The 2 methods return tokens (
UnsafeCellRefToken
andUnsafeCellMutToken
, respectively) that implementDrop
so that the beginning of the access can be marked by the invocation of theguard_*_access
methods and the end of the access is marked by the release of the token object.I appologize in advance for the lack of proper documentation and tests to accompany the feature. However, I did add doc comments.
This PR also allows the
T
parameter ofUnsafeCell<T>
to be unsized (T: ?Sized
) to mirrorstd::cell::UnsafeCell
, although I can break that out into a separate PR if needed.