| Crates.io | to-true |
| lib.rs | to-true |
| version | 0.1.2 |
| created_at | 2025-05-21 00:52:41.255155+00 |
| updated_at | 2025-06-11 10:52:16.970282+00 |
| description | Convenient conversion of bool states |
| homepage | |
| repository | https://github.com/A4-Tacks/to-true-rs |
| max_upload_size | |
| id | 1682736 |
| size | 5,918 |
Convenient conversion of bool states
# use to_true::ToTrue;
let mut state = false;
let mut n = 0;
assert_eq!(state.to_true(|| n += 1), Some(()));
assert_eq!((n, state), (1, true));
assert_eq!(state.to_true(|| n += 1), None);
assert_eq!((n, state), (1, true));
assert_eq!(state.to_false(|| n += 1), Some(()));
assert_eq!((n, state), (2, false));
assert_eq!(state.to_false(|| n += 1), None);
assert_eq!((n, state), (2, false));