Derive Macro WIT_From_Into

Source
#[derive(WIT_From_Into)]
{
    // Attributes available to this derive:
    #[wit_type_name]
    #[rename_field]
}
Expand description

Derives From<> And Into<> typeclasses for wit-bindgen generated data types (e.g. WitPerson) and custom domain data types (e.g. Person). So it’s possible to write code like this:

 let person = Person {
    name: "John Doe".to_owned(),
    age: 42,
 };

 let converted: WitPerson = person.into();

#[wit_type_name(WitPerson)] is optional. Defines name of the wit-bindgen generated data type. Default is name of this data type prepanded with ‘Wit’.

#[rename_field("age2")] is optional. Anotates field and specify field name in the other data type, in case it’s different.

§Example:

 pub struct WitPerson {
     pub title: String,
     pub age: i32,
 }


 #[derive(golem_rust_macro::WIT_From_Into)]
 #[wit_type_name(WitPerson)]
 pub struct Person {

     #[rename_field("title")]
     pub name: String,
      
     pub age: i32
 }