try-drop 0.2.0

Batteries included error handling mechanisms for drops which can fail
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use try_drop::drop_strategies::{AdHocFallibleDropStrategy, AdHocDropStrategy};
use try_drop::test_utils::{ErrorsOnDrop, Fallible};
use try_drop::PureTryDrop;

fn main() {
    let fallible_try_drop_strategy = AdHocFallibleDropStrategy(|error| {
        println!("an error occurred from a drop: {error}");
        anyhow::bail!("this try drop strategy failed")
    });
    let fallback_try_drop_strategy =
        AdHocDropStrategy(|error| println!("error from the failed try drop strategy: {error}"));

    let errors =
        ErrorsOnDrop::<Fallible, _>::given(fallible_try_drop_strategy, fallback_try_drop_strategy)
            .adapt();
    drop(errors);
}