Skip to content

A tiny proc macro to make all your struct fields optional

License

Notifications You must be signed in to change notification settings

dfm/discretionary

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Discretionary

status version

A tiny procedural macro to make all your struct fields optional. For now, this package is essentially trivial, although it might be useful if you have some huge struct that needs to have all its field types converted from T to Option<T>. (I needed that and now this exists!)

Usage

Add discretionary as a dependency in your Cargo.toml:

[dependencies]
discretionary = "0.1"

Then decorate your struct with the #[make_optional] macro. That's it!

For example, the following

use discretionary::make_optional;

#[make_optional]
struct ExampleStruct {
    id: usize,
    name: String,
}

will be re-written to something like

struct ExampleStruct {
    id: Option<usize>,
    name: Option<String>,
}

About

A tiny proc macro to make all your struct fields optional

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages