constructor-macro

Crates.ioconstructor-macro
lib.rsconstructor-macro
version0.4.2
sourcesrc
created_at2019-06-08 17:54:09.041207
updated_at2019-07-30 13:39:49.282166
descriptionDerive constructor macros for structs
homepage
repositoryhttps://github.com/thisKai/constructor-macro
max_upload_size
id139850
size11,312
(thisKai)

documentation

README

constructor-macro

Cargo.toml

[dependencies]
constructor-macro = "0.4"

Example

Rust 2018

use constructor_macro::ConstructorMacro;

#[derive(ConstructorMacro)]
pub struct Thing {
    #[default(1)]
    pub field1: i32,
    pub field2: i32,
}

fn main() {
    let thing1 = Thing!();
    assert_eq!(thing1.field1, 1);
    assert_eq!(thing1.field2, 0);

    let thing2 = Thing! { field1: 2 };
    assert_eq!(thing2.field1, 2);
    assert_eq!(thing2.field2, 0);

    let thing3 = Thing! {
        field1: 0,
        field2: 100,
    };
    assert_eq!(thing3.field1, 0);
    assert_eq!(thing3.field2, 100);
}

Rust 2015

#[macro_use]
extern crate constructor_macro;

...
Commit count: 48

cargo fmt