use std::panic;
use thread_scoped_ref::{scoped, thread_scoped_ref, with};
pub struct MyValue(String);
thread_scoped_ref!(MY_VALUE, MyValue);
#[test]
pub fn panic_within_scope_and_cleanup() {
let value = MyValue("The value".to_string());
let result = panic::catch_unwind(|| {
scoped(&MY_VALUE, &value, || {
with(&MY_VALUE, |maybe_value| {
assert_eq!(maybe_value.unwrap().0, "The value")
});
panic!("shit happens!");
});
});
assert!(result.is_err());
with(&MY_VALUE, |maybe_value| {
assert_eq!(true, maybe_value.is_none())
});
}