default_macro

Crates.iodefault_macro
lib.rsdefault_macro
version0.2.1
sourcesrc
created_at2019-02-08 20:03:47.500166
updated_at2020-04-25 13:18:16.539992
descriptionMy default!() macro
homepagehttps://github.com/mikhail-m1/default_macro
repositoryhttps://github.com/mikhail-m1/default_macro
max_upload_size
id113577
size4,953
Mikhail Modin (mikhail-m1)

documentation

README

default! macro for Rust

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} 
    });
}
Commit count: 2

cargo fmt