macro_rules! derive_dyn_traits {
($trait:ident use $registry:ty = $reginit:expr) => { ... };
($trait:ident) => { ... };
}Expand description
§Generate DynXso and MayContain trait implementations
This macro generates trait DynXso and MayContain trait
implementations for a given trait. For more background information on when
that is a useful thing to have, see the dynxso
module.
§Syntax
This macro can be called in two forms:
derive_dyn_traits!(Trait)uses the defaultBuilderRegistryasDynXso::Registrytype and is only available ifxsois built with the"std"feature.derive_dyn_traits!(Trait use Type = expr)whereTypeis used asDynXso::Registry, initialized withexpr. This form is available for any set of crate features.
§Example
When std is enabled, the simple syntax can be used.
use xso::derive_dyn_traits;
trait Foo: Any {}
derive_dyn_traits!(Foo); Note that the trait this macro is called on must have a bound on
Any, otherwise the generated code will not compile:
ⓘ
use xso::derive_dyn_traits;
trait Foo {}
derive_dyn_traits!(Foo);
// ↑ will generate a bunch of errors about incompatible typesIf the std feature is not enabled or if you want to use another
Registry for whichever reason, the explicit form can be used:
use xso::derive_dyn_traits;
trait Foo: Any {}
struct Registry { /* .. */ }
derive_dyn_traits!(Foo use Registry = Registry { /* .. */ });In that case, you should review the trait requirements of the
DynXso::Registry associated type.