2 releases
0.1.1 | Jun 8, 2021 |
---|---|
0.1.0 | Jun 8, 2021 |
#37 in #contents
6KB
65 lines
safe_cell
This crate exports the SafeCell
type, a wrapper type that enables safe exterior mutability for arbitrary contents.
The use case is similar to that of the standard library's UnsafeCell
¹ type but, by virtue of being specialized for situations where it can be statically proven that no unsound access occurs, SafeCell
is fully usable in safe code. In addition, the implementation is easily proven to be fully sound, making SafeCell
a great alternative to UnsafeCell
in safety-critical code.
As the implementation is incredibly lightweight and does not make use of any additional synchronization primitives or dynamic borrow tracking, it has negligible overhead (and hence functions as a true "zero-cost abstraction"²).
lib.rs
:
safe_cell
This crate exports the SafeCell
type, a wrapper type that enables safe
exterior mutability for arbitrary contents.
The use case is similar to that of the standard library's
UnsafeCell
¹ type but, by virtue of being specialized for
situations where it can be statically proven that no unsound access
occurs, SafeCell
is fully usable in safe code. In addition, the
implementation is easily proven to be fully sound, making SafeCell
a
great alternative to UnsafeCell
in safety-critical code.
As the implementation is incredibly lightweight and does not make use of any additional synchronization primitives or dynamic borrow tracking, it has negligible overhead (and hence functions as a true "zero-cost abstraction"²).