Perforate
Perforate generates variants of a struct to allow a struct field to be "split" from the rest of the struct as in a split borrow.
This is similar in effect to using mem::take or one of the other replacement functions, except it can be performed on fields that don't implement Default or when a suitable placeholer can't be constructed.
Usage
Perforate an owned struct on the stack.
use Perforate;
let test_struct = TestStruct;
let = test_struct.perforate_one;
assert_eq!;
assert_eq!;
assert_eq!;
let original = perforated.replace_perf;
assert_eq!;
assert_eq!;
Or perforate a struct in an owned box.
use Perforate;
let test_struct = Boxnew;
let = boxed_perforate_one;
assert_eq!;
assert_eq!;
let original_box = boxed_replace_one;
assert_eq!;
assert_eq!;
Caveats
If a struct has generic parameters or lifetimes that are used only by a field marked with the #[perforate] attribute, you must add a PhantomData to your struct to prevent compile errors. In addition, you cannot perforate a field with a generic type parameter on stable until the issue is merged.
You may access the other "unperforated" fields of the perforated struct, however the perforated version of the struct is a new type and does not have any of the trait implementations from its progenitor. This includes a custom Drop trait. So if your struct needs special cleanup behavior you must reassemble it before dropping.