Projecture
This is in a proof of concept state and also internally uses a lot of not yet battle-tested unsafe code so use it on your own risk meanwhile if you are good with unsafe rust i would appreciate a soundness review
Allows to do almost arbitrary type projections. In comparison to other crates that do similar things it is not just more generic as such requires much less transitive dependencies and also does not impose additional requirements on target struct, if target struct is located in external crate that crate does not have to explicitly add a support such projection.
Although as of now this crate doesn't support enums yet, but it will be added later.
Currently can do following type of projections
- Destructuring projection (similar to usual
let <pattern>but also supports deref pattern, and also works if struct implementsDropwhich is just not called). Note that due to limitations of declaration macros currently unmentioned fields are leaked. - Reference(
&,&mut) projection (similar to match ergonomics inlet <pattern>but also supports deref pattern) PinprojectionCellprojectionMaybeUninitprojectionAtomic(fromatomiccrate) projectionOptionprojection (which works together with other kinds of projections)RefCellguards projection- raw pointers projections (
*const T,*mut T,NonNull<T>)
Also, where possible, projections can additionally project through a Deref type.
Here is a general overview of what you can do, see [project]! macro for more usage details.
# use Cell;
# use PhantomPinned;
# use Pin;
# use Rc;
# use Atomic;
# use project;
;
Also allows dependent crates to define their own projections via traits.
see atomic module for example of how to do a projection of a transparent field wrapper
or Pin for doing projections on a custom reference type
MSRV: 1.54 License: MIT