[][src]Crate multi_structs

A macro for generating a merged struct from multiple sub-structs.


use multi_structs::multi_structs;

multi_structs! {
    /// The merged struct.
    pub struct Merged {
        /// Foo
        pub foo: struct Foo {
            /// a
            pub a: i32,
            /// b
            pub b: i64,
        /// Bar
        pub bar: struct Bar {
            /// c
            pub c: usize,
            /// d
            pub d: String,

fn main() {
    let foo = Foo { a: 1, b: 2 };
    let bar = Bar { c: 3, d: "aaa".to_string() };
    println!("{:?}, {:?}", foo, bar);
    let merged = Merged::new(foo, bar);
    println!("{:?}", merged);
    let (foo, bar) = merged.split();
    println!("{:?}, {:?}", foo, bar);

See example_generated for documentation of code generated by the above multi_structs! expansion.


Attributes can be attached to any struct and field involved.


The following methods are defined for the merged struct:

  • new: create the new merged struct from multiple sub-structs.
  • split: split the merged struct into the sub-structs.


The visibility of structs and fields is taken directly from their definitions. For the generated methods new and split, the visibility of the merged struct is assumed.



This module shows an example of code generated by the macro. IT MUST NOT BE USED OUTSIDE THIS CRATE.