Skip to content

xohmz/conditional-assignment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

conditional-assignment

GitHub Workflow Status (with branch) Crates.io Crates.io (latest)

This is a very simple, small crate to help make conditional assignments more ergonomic.

Intent

The goal is to make the below look a little better.

let condition = 0 < 1;
let outcome = if condition {
    "true"
} else {
    "false"
};

Examples

Basic

Eager

use conditional_assignment::Pick;

let condition = 0 < 1;
let outcome = condition.pick("true", "false");

Lazy

use conditional_assignment::Pick;

let condition = 0 < 1;
let outcome = condition.pick_lazy(
    || {
        // This won't be evaluated and
        // panic when condition is false.
        assert!(condition);
        "true"
    },
    || {
        // This won't be evaluated and
        // panic when condition is true.
        assert!(!condition);
        "false"
    },
);

Minimum Supported Rust Version (MSRV)

According to cargo-msrv, the MSRV is 1.56.1. Given how simple this crate is, I wouldn't be surprised if the MSRV is lower, but I didn't check. Try it!

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

This is a very simple, small crate to help make conditional assignments more ergonomic.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages