extern crate r; use r::stable_rc::StableArc; use std::ops::Deref; #[test] fn test_stable_rc_ok() { let rc = StableArc::new(1usize); { println!("Start: Should not generate any output"); let mut storage = Vec::new(); r::stable_rc::disable(); for _ in 0..10000 { storage.push(rc.clone()); } r::stable_rc::enable(); let mut sum = 0usize; for x in &storage { sum = sum + *x.deref(); } println!("Finished: {}", sum); r::stable_rc::disable(); } r::stable_rc::enable(); StableArc::try_unwrap(rc).expect("Must be ok"); } #[test] fn test_stable_rc_not_ok() { let rc = StableArc::new_configure(1usize, 10_000_000_000, 19); let val; { println!("Start: Should generate some error message"); let mut storage = Vec::new(); for _ in 0..10 { storage.push(rc.clone()); } let mut sum = 0usize; for x in &storage { sum = sum + *x.deref(); } val = sum; } println!("Finished {}", val); StableArc::try_unwrap(rc).expect("Must be ok"); }