optfield-lite

Crates.iooptfield-lite
lib.rsoptfield-lite
version0.1.0
created_at2025-04-01 14:01:22.416361+00
updated_at2025-04-01 14:01:22.416361+00
descriptionA macro to generate a new struct with fields wrapped in Option.
homepage
repositoryhttps://github.com/PRO-2684/Candy-Pile
max_upload_size
id1614905
size5,143
PRO (PRO-2684)

documentation

README

optfield-lite

GitHub License Crates.io Version Crates.io Total Downloads docs.rs free of syn

A macro to generate a new struct with fields wrapped in Option. Lite version of optfield.

Usage

Recommended to work with macro_rules_attr, which provides nice syntactic sugar:

use optfield_lite::optfield;
use macro_rules_attr::apply;

#[apply(optfield(OptTest))]
/// My test struct
struct Test {
    pub a: u32,
    b: u32,
}

This will generate a struct OptTest with the following fields:

/// My test struct
struct OptTest {
    pub a: Option<u32>,
    b: Option<u32>,
}

Note that the generated struct will have the same attributes and visibility as the original struct. You can also use it directly, which produces the same result:

use optfield_lite::optfield;

optfield! {
    /// My test struct
    struct Test {
        pub a: u32,
        b: u32,
    }(OptTest)
}

Comparison

Commit count: 14

cargo fmt