5 unstable releases

new 0.3.2 Jan 8, 2025
0.3.1 Mar 20, 2024
0.3.0 Mar 20, 2024
0.2.0 Mar 20, 2024
0.1.0 Mar 20, 2024

#1731 in Development tools

Download history 16/week @ 2024-09-22 9/week @ 2024-09-29 9/week @ 2024-12-08 1/week @ 2024-12-15 149/week @ 2025-01-05

151 downloads per month
Used in 2 crates

MIT/Apache

17KB
288 lines

jdefault

Crates.io Crates.io License

Cargo.toml

[dependencies]
jdefault_derive = "0.3.2"

Usage

use jdefault_derive::Jdefault;


#[derive(Debug, PartialEq, Eq, Jdefault)]
pub struct StructExample<'a> {
    pub value1: u16,
    #[jd(default=18)]
    pub value2: u16,
    #[jd(default="\"jankincai\".to_string()")]
    pub value3: String,
    #[jd(default="\"jankincai\"")]
    pub value4: &'a str,
    #[jd(default=b"\x00\x01\x02")]
    pub value5: &'a [u8],
    pub body: StructExampleBody,
}


#[derive(Debug, PartialEq, Eq, Jdefault)]
pub struct StructExampleBody {
    #[jd(default=1)]
    pub value: u16,
}


#[test]
fn test_jdefault() {
    let value = StructExample::default();

    assert_eq!(value, StructExample {
        value1: 0,
        value2: 18,
        value3: "jankincai".to_string(),
        value4: "jankincai",
        value5: b"\x00\x01\x02",
        body: StructExampleBody {
            value: 1,
        }
    });
}

Dependencies

~190KB