Crates.io | conditional-assignment |
lib.rs | conditional-assignment |
version | 0.2.0 |
source | src |
created_at | 2023-12-25 18:44:56.506595 |
updated_at | 2023-12-30 03:10:06.397057 |
description | This is a very simple, small crate to help make conditional assignments more ergonomic. |
homepage | |
repository | https://github.com/xohmz/conditional-assignment |
max_upload_size | |
id | 1080385 |
size | 18,275 |
This is a very simple, small crate to help make conditional assignments more ergonomic.
The goal is to make the below look a little better.
let condition = 0 < 1;
let outcome = if condition {
"true"
} else {
"false"
};
use conditional_assignment::Pick;
let condition = 0 < 1;
let outcome = condition.pick("true", "false");
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"
},
);
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!
Licensed under either of
at your option.
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.