use std::cell::RefCell; use std::rc::Rc; use niom_webrtc::components::ErrorActions; #[test] fn report_and_clear_delegate_to_callbacks() { let reported: Rc>> = Rc::new(RefCell::new(Vec::new())); let cleared: Rc> = Rc::new(RefCell::new(0)); let report_fn = { let reported = Rc::clone(&reported); Rc::new(move |msg: String| { reported.borrow_mut().push(msg); }) as Rc }; let clear_fn = { let cleared = Rc::clone(&cleared); Rc::new(move || { *cleared.borrow_mut() += 1; }) as Rc }; let actions = ErrorActions::new(report_fn, clear_fn); actions.report("boom"); actions.report("bam"); actions.clear(); assert_eq!(reported.borrow().as_slice(), ["boom", "bam"]); assert_eq!(*cleared.borrow(), 1); }