macro_rules! late_struct {
(
$($ty:ty $(=> $erase_to:ty)?),*
$(,)?
) => { ... };
}Expand description
Implements the LateStruct trait for the specified $ty type, turing it into a marker type
that can be used to refer to a late-initialized structure.
See the crate level documentation for examples of this macro in action as well as a step-by-step guide on how to use it.
You can attach fields onto this type using the late_field! macro and can
instantiate the structure defined by this macro using the LateInstance
struct. Either operation can occur anywhere within the crate graph of a project; fields can be
added to the structure in crates which are downstream to crates which instantiate that
structure.
The $ty type need only be Sized and live for 'static. No types in this macro invocation
may involve unbound generic parameters.
You can specify more than one type onto which LateStruct should be implemented with this
macro.
§The EraseTo Parameter
The optional $erase_to type specifies the type all field values should be able to upcast (i.e.
“erase”) to. Generally, this type is a trait object. For instance, if you specify dyn Any + Send + Sync, all field values will have to implement Any, Send, and
Sync. If $erase_to is omitted, the type will default to dyn 'static + fmt::Debug, which
would entail that all fields in the struct must implement the Debug trait.
In addition to the trait constraints $erased_to places on fields, late_field! automatically
enforces that all fields live for 'static, be Sized, and implement the Default trait.
It is this Default trait implementation which is used to initialize instances of this struct.
Traits such as Eq, Clone, and Hash are not dyn compatible and thus cannot be
used directly inside the bounds of the $erase_to type. You can work around this restriction by
using the DynEq, DynClone, and
DynHash traits respectively, which are dyn compatible while still encoding
the necessary constraints.