https://github.com/upsuper/multi-structs
Macro for generating a merged struct from multiple sub-structs
https://github.com/upsuper/multi-structs
Last synced: 3 months ago
JSON representation
Macro for generating a merged struct from multiple sub-structs
- Host: GitHub
- URL: https://github.com/upsuper/multi-structs
- Owner: upsuper
- License: mit
- Created: 2018-05-27T14:37:42.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2020-01-13T10:41:31.000Z (over 5 years ago)
- Last Synced: 2025-03-24T06:45:28.066Z (4 months ago)
- Language: Rust
- Size: 6.84 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# multi-structs
[](https://travis-ci.org/upsuper/multi-structs)
[](https://docs.rs/multi-structs)A macro for generating a merged struct from multiple sub-structs.
## Example
```rust
#[macro_use]
extern crate multi_structs;multi_structs! {
/// The merged struct.
#[derive(Debug)]
pub struct Merged {
/// Foo
#[derive(Debug)]
pub foo: struct Foo {
/// a
pub a: i32,
/// b
pub b: i64,
}
/// Bar
#[derive(Debug)]
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);
}
```