lazytry

Crates.iolazytry
lib.rslazytry
version0.1.0
sourcesrc
created_at2022-07-27 10:54:12.664079
updated_at2022-07-27 10:54:12.664079
descriptionProviding failable lazy values
homepage
repositoryhttps://github.com/snylonue/lazytry
max_upload_size
id633826
size6,914
(snylonue)

documentation

README

lazytry

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.

Commit count: 12

cargo fmt