macro_rules! new_box {
($dyn_trait:ty, $ctor:expr) => { ... };
}Expand description
Defines the template used to create every instance in a linked::Box<T> object family.
This macro is meant to be used in the context of creating a new linked instance of
T that is meant to be always expressed via an abstraction (dyn SomeTrait).
§Arguments
$dyn_trait- The trait object that the linked object is to be used as (e.g.dyn SomeTrait).$ctor- The Self-expression that serves as the template for constructing new linked instances on demand. This will move-capture any referenced state. All captured values must be thread-safe (Send+Sync+'static).
§Example
// If using linked::Box, do not put `#[linked::object]` on the struct.
// The linked::Box itself is the linked object and our struct is only its contents.
struct XmlConfig {
config: String,
}
impl XmlConfig {
pub fn new_as_config_source() -> linked::Box<dyn ConfigSource> {
linked::new_box!(
dyn ConfigSource,
Self {
config: "xml".to_string(),
}
)
}
}See examples/linked_box.rs for a complete example.