Consumes this [`Store`], destroying it, and returns the underlying data.
(mut self)
| 868 | |
| 869 | /// Consumes this [`Store`], destroying it, and returns the underlying data. |
| 870 | pub fn into_data(mut self) -> T { |
| 871 | self.run_manual_drop_routines(); |
| 872 | |
| 873 | // This is an unsafe operation because we want to avoid having a runtime |
| 874 | // check or boolean for whether the data is actually contained within a |
| 875 | // `Store`. The data itself is stored as `ManuallyDrop` since we're |
| 876 | // manually managing the memory here, and there's also a `ManuallyDrop` |
| 877 | // around the `Box<StoreInner<T>>`. The way this works though is a bit |
| 878 | // tricky, so here's how things get dropped appropriately: |
| 879 | // |
| 880 | // * When a `Store<T>` is normally dropped, the custom destructor for |
| 881 | // `Store<T>` will drop `T`, then the `self.inner` field. The |
| 882 | // rustc-glue destructor runs for `Box<StoreInner<T>>` which drops |
| 883 | // `StoreInner<T>`. This cleans up all internal fields and doesn't |
| 884 | // touch `T` because it's wrapped in `ManuallyDrop`. |
| 885 | // |
| 886 | // * When calling this method we skip the top-level destructor for |
| 887 | // `Store<T>` with `mem::forget`. This skips both the destructor for |
| 888 | // `T` and the destructor for `StoreInner<T>`. We do, however, run the |
| 889 | // destructor for `Box<StoreInner<T>>` which, like above, will skip |
| 890 | // the destructor for `T` since it's `ManuallyDrop`. |
| 891 | // |
| 892 | // In both cases all the other fields of `StoreInner<T>` should all get |
| 893 | // dropped, and the manual management of destructors is basically |
| 894 | // between this method and `Drop for Store<T>`. Note that this also |
| 895 | // means that `Drop for StoreInner<T>` cannot access `self.data`, so |
| 896 | // there is a comment indicating this as well. |
| 897 | unsafe { |
| 898 | let mut inner = ManuallyDrop::take(&mut self.inner); |
| 899 | core::mem::forget(self); |
| 900 | ManuallyDrop::take(&mut inner.data_no_provenance) |
| 901 | } |
| 902 | } |
| 903 | |
| 904 | /// Configures the [`ResourceLimiter`] used to limit resource creation |
| 905 | /// within this [`Store`]. |