optionee 0.2.0

The macro to create option struct easily.
Documentation
  • Coverage
  • 25%
    1 out of 4 items documented1 out of 1 items with examples
  • Size
  • Source code size: 26.78 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 6.03 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • just-do-halee/optionee
    2 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • just-do-halee

optionee

The macro to create option struct easily. (no-std support)

Crates.io Licensed Twitter

| Docs | Latest Note |

[dependencies]
optionee = "0.2.0"

or

[dependencies]
optionee = { version = "0.2.0", default-features = false } # no-std(alloc)

How to

optionee! {

    InputOption {

        Id {
            min_length: u8 [>] 2, "id must be more than 3 bytes."
            max_length: u8 [<] 13, "id must be less than 12 bytes."
        }
        Password {
            encrypt: bool [=] true
            min_length: u8 [>] 5, "psasword must be more than 6 bytes."
            max_length: u8 [<] 20, "psasword must be less than 19 bytes."
        }

    }

}

let mut id_t = InputOption.Id();

let user_input = 20;

assert!(id_t.min_length.check(user_input).is_ok());

More Examples

orderable! {

    pub struct Job {
        id: u32[*], // mark for comparing
        name: String,
        salary: u16[*], // ..
    }

}
optionee! {

    pub TermOption {
            Password {
                max_opportunity: u8 [=] 3, "if you don't really remember your own password, please cider o restart with --reset flag."
                encrypt: bool [=] false
                min_length: u8 [>] 7, "password must be more than 8 lengths bytes."
                max_length: u8 [<] 21, "password must be less than 20 lengths bytes."
            }
    }
    SecondPrivateOpt {
            AnyName {
                name: String [=] "john".to_string()
                job: Job [>] Job::new(0, "sales".to_string(), 29), "id must be more than 1, salary 30"
            }
            OldPerson {
                name: &'static str [=] "mia"
                age: u8 [>] 52
            }

    }

}

let mut t1 = TermOption.Password().encrypt(true).min_length(3);
t1.min_length
    .set_error_message(Some("password must be more than 3 lengths bytes."));

assert!(t1.encrypt.get_value());
assert!(t1.min_length.check(4).is_ok());

let t2 = SecondPrivateOpt
    .AnyName()
    .job(Job::new(0, "writer".to_string(), 29));

assert!(t2.name.check("john".to_string()).is_ok());
assert!(t2.job.check(Job::new(1, "artist".to_string(), 30)).is_ok());