Captur
Starting in Rust 2021, Rust will no longer capture whole structs and instead will only capture a disjoint set of the fields used in a closure. In some cases, it is necessary to capture the structs to retain a particular drop order. This macro will capture the struct within the closure, ensuring the correct drop order.
The Fix
The typical fix to this problem is to create an unused reference to the struct.
let some_struct = new;
let result =
While this is trivial to implement in closures where capturing is required, without a comment it, the meaning of the unused line is difficult to determine. This macro provides a self documenting and potentially more concise way to capture the structs.
Installation and Usage
[]
= "0.1"
use capture;
License
Captur is released under the ISC license. See LICENSE.