#[derive(Collect)]
{
// Attributes available to this derive:
#[collect]
}
Expand description
Derives the Collect trait needed to trace a gc type.
To derive Collect, an additional attribute is required on the struct/enum called
collect. This has several optional arguments, but the only required argument is the derive
strategy. This can be one of
#[collect(require_static)]- Adds a'staticbound, which allows for a no-op trace implementation. This is the ideal choice where possible.#[collect(no_drop)]- The typical safe tracing derive strategy which only has to add a requirement that your struct/enum does not have a custom implementation ofDrop.#[collect(unsafe_drop)]- The most versatile tracing derive strategy which allows a custom drop implementation. However, this strategy can lead to unsoundness if care is not taken (see the above explanation ofDropinteractions).
The collect attribute also accepts a number of optional configuration settings:
#[collect(bound = "<code>")]- Replaces the default generatedwhereclause with the given code. This can be an empty string to add nowhereclause, or otherwise must start with"where", e.g.,#[collect(bound = "where T: Collect")]. Note that this option is ignored forrequire_staticmode since the only bound it produces isSelf: 'static. Also note that providing an explicit bound in this way is safe, and only changes the trait bounds used to enable the implementation ofCollect.
Options may be passed to the collect attribute together, e.g., #[collect(no_drop, bound = "")].
The collect attribute may also be used on any field of an enum or struct, however the
only allowed usage is to specify the strategy as require_static (no other strategies are
allowed, and no optional settings can be specified). This will add a 'static bound to the
type of the field (regardless of an explicit bound setting) in exchange for not having
to trace into the given field (the ideal choice where possible). Note that if the entire
struct/enum is marked with require_static then this is unnecessary.