Attribute Macro extruct_macros::extruct_from

source ·
#[extruct_from]
Expand description

An attribute macro implements the std::convert::From trait for an annotated non-generic named struct using a “superstruct” specified as the attribute parameter as a source type.

extruct_from accepts a single parameter which is a non-generic type name referring to a named struct.

struct SuperStruct {
    one_field: String,
    another_field: u32,
    and_one_more: char,
}

#[extruct_from(SuperStruct)]
struct SubStruct {
    and_one_more: String,
}

let sup = SuperStruct {
    one_field: "str".to_owned(),
    another_field: 1135,
    and_one_more: 'x',
};

let sub: SubStruct = sup.into();