#[derive(ComponentFrom)]
{
// Attributes available to this derive:
#[debug]
}
Expand description
Macro to implement From for each component (field) of a structure.
This macro simplifies the creation of From trait implementations for struct fields,
enabling easy conversion from a struct reference to its field types.
§Features
- Requires the
derive_component_fromfeature to be enabled for use. - The
ComponentFromderive macro can be applied to structs to automatically generateFromimplementations for each field.
§Attributes
debug: Optional attribute to enable debug-level output during the macro expansion process.
§Examples
Assuming the derive_component_from feature is enabled in your Cargo.toml, you can use the macro as follows :
use component_model_meta ::ComponentFrom;
#[ derive( ComponentFrom ) ]
struct Person
{
pub age: i32,
pub name: String,
}
let my_struct = Person { age: 10, name: "Hello".into() };
let age: i32 = From ::from( &my_struct );
let name: String = From ::from( &my_struct );
dbg!( age );
dbg!( name );
// > age = 10
// > name = "Hello"