#constructor #derive #auto-constructor

macro bin crabstructor

Simple constructor generator for named structures

3 unstable releases

0.2.1-beta Sep 4, 2024
0.2.0-beta Sep 4, 2024
0.1.0-beta Aug 25, 2024

#389 in Procedural macros

Download history 121/week @ 2024-08-20 24/week @ 2024-08-27 266/week @ 2024-09-03 1/week @ 2024-09-10 4/week @ 2024-09-17 7/week @ 2024-09-24 8/week @ 2024-10-01 7/week @ 2024-10-08 10/week @ 2024-10-15 4/week @ 2024-10-29 9/week @ 2024-11-05

93 downloads per month

Apache-2.0

11KB
207 lines

CrabStructor v0.2.0-beta

Init with literal

#[derive(Constructor, PartialEq, Debug)]
struct Example {
    #[init(10)]
    field: i32,
}

assert_eq!(Example::new(), Example {field: 10});

Call new func

#[derive(Constructor, PartialEq, Debug)]
struct Example {
    #[new("string")]
    field: Arc<String>,
}

assert_eq!(Example::new(), Example {field: Arc::new("string".into())});
#[derive(Constructor, PartialEq, Debug)]
struct Example {
    #[new(arc_string: String)]
    field: Arc<String>,
}

assert_eq!(Example::new("string".to_string()), Example {field: Arc::new("string".into())});

Alert

This is dev version of lib

Supported types

  1. All strings, which implement "Into" trait
  2. All rust nums
  3. Bool types

Dependencies

~220–660KB
~16K SLoC