Into inner drop
Safe helper for types that should implement both Drop
and .into_inner()
method.
About
There's a repeating pattern where people want to have a type that does something on drop,
but also want to be able to avoid dropping and destructure the type using some method that
takes self
.
Furhter, sometimes people want to destructure the type in drop
implementation, which isn't
safe due to it being passed by mutable refernece.
Hand-rolling unsafe
code was neccessary until this crate existed. This crate takes the
responsibility for ensuring that the drop impl is sound. More eyes, less bugs.
This crate is no_std
.
Example
Let's say you want to have a special type that prints a string on drop, but with ability to take out the string without printing. This is how you would approach it using this crate:
// Not strictly neccessary, but helps encapsulate the inner representation.
use IntoInnerHelper;
// Public representation
/// A String that is printed when dropped.
;
As you can see, the code has some boilerplate, but no unsafe
. I'm already trying to come up
with a macro to make it much easier. See the appropriate issue on GitHub to participate.
License
MITNFA