Crates.io | default_macro |
lib.rs | default_macro |
version | 0.2.1 |
source | src |
created_at | 2019-02-08 20:03:47.500166 |
updated_at | 2020-04-25 13:18:16.539992 |
description | My default!() macro |
homepage | https://github.com/mikhail-m1/default_macro |
repository | https://github.com/mikhail-m1/default_macro |
max_upload_size | |
id | 113577 |
size | 4,953 |
Sometimes you want to create nested structures, set values for some the fields and use default value for most of the other, for example:
use default_macro::default;
#[derive(Default)]
struct Window { title: &str, border: Border, /* 10 other fields */ }
#[derive(Default)]
struct Border { width: f64, /* 5 other fields*/ }
fn foo() {
let w1 = Window {
title: "Test",
border: Border {
width: 10.0,
..Border::Default},
..Window::default()
};
// with the macros:
let w2 = default!( Window {
title: "Test",
border: Border { width: 10.0}
});
}