use super::*;
use fmt::Write as _;
+use std::panic::{AssertUnwindSafe, catch_unwind, resume_unwind};
mod demo;
use demo::{List, HeadAndTail};
l.check_consistency();
assert_eq!(l.head_and_tail_mut(), H::Both(&mut s("one"), &mut s("ho")));
+ catch_unwind(AssertUnwindSafe(|| {
+ l.temporarily_prepend(s("t"), |l| {
+ l.check_consistency();
+ assert_eq!(l.front(), Some(&s("t")));
+ panic!("yikes");
+ });
+ })).unwrap_err();
+ l.check_consistency();
+ assert_eq!(l.head_and_tail_mut(), H::Both(&mut s("one"), &mut s("ho")));
+
write!(l.front_mut().unwrap(), "!").unwrap();
assert_eq!(l.pop_front(), Some(s("one!"))); l.check_consistency();
assert_eq!(l.front(), Some(&s("hi"))); l.check_consistency();
data: T,
then: impl FnOnce(&Self) -> R,
) -> R {
- use std::panic::{AssertUnwindSafe, catch_unwind, resume_unwind};
-
let mut tmp_node = Node {
data,
next: None,