Crates.io | lazytry |
lib.rs | lazytry |
version | 0.1.0 |
source | src |
created_at | 2022-07-27 10:54:12.664079 |
updated_at | 2022-07-27 10:54:12.664079 |
description | Providing failable lazy values |
homepage | |
repository | https://github.com/snylonue/lazytry |
max_upload_size | |
id | 633826 |
size | 6,914 |
lazytry
aims for lazy data evaluation which may fail.
use lazytry::unsync::LazyTry;
let lazy: LazyTry<i32, _> = LazyTry::new(|| "1".parse());
assert_eq!(lazy.force().unwrap(), &1);
assert_eq!(lazy.force().unwrap(), &1);
use lazytry::unsync::LazyTryFn;
use std::num::{IntErrorKind, ParseIntError};
let lazy: LazyTryFn<i32, ParseIntError> = LazyTry::new(|| "a".parse());
assert_eq!(
*lazy.force().unwrap_err().into_err().unwrap().kind(),
IntErrorKind::InvalidDigit
);
The current code is quite experimental, including unproved use of unsafe (impl Sync), lack of documentation and a weird and incompleted api.