generic-new

Crates.iogeneric-new
lib.rsgeneric-new
version0.2.0
sourcesrc
created_at2022-03-31 22:50:12.302803
updated_at2022-04-07 19:22:11.766975
descriptionA derive macro which generates an ergonomic constructor with shortcuts for certain types.
homepage
repositoryhttps://github.com/aatifsyed/generic-new
max_upload_size
id559945
size25,623
Aatif Syed (aatifsyed)

documentation

https://docs.rs/generic-new

README

generic-new

crates-io docs-rs github

A derive macro which generates an ergonomic constructor with shortcuts for certain types.

use generic_new::GenericNew;

#[derive(GenericNew)]
struct Foo {
    s: String,      // -> impl AsRef<str>
    v: Vec<usize>,  // -> impl IntoIterator<Item = usize>
    i: Vec<String>, // -> impl IntoIterator<Item = impl AsRef<str>>
    p: PathBuf,     // -> impl AsRef<Path>
    #[generic_new(ignore)]
    o: String,      // Turn off magic conversion for some fields
    #[generic_new(ty = impl Into<usize>, converter = |u|Into::into(u))]
    u: usize,       // Custom converters are supported
}

Foo::new(
    "hello",
    [1, 2, 3],
    ["a", "b", "c"],
    "path/to/foo",
    String::from("world"),
    1u16,
);

License: MIT

Commit count: 13

cargo fmt