很漂亮的一段case,来自std
library/alloc/tests/linked_list.rs
#[test]
fn test_drop() {
static mut DROPS: i32 = 0;
struct Elem;
impl Drop for Elem {
fn drop(&mut self) {
unsafe {
DROPS += 1;
}
}
}
let mut ring = LinkedList::new();
ring.push_back(Elem);
ring.push_front(Elem);
ring.push_back(Elem);
ring.push_front(Elem);
drop(ring);
assert_eq!(unsafe { DROPS }, 4);
}
1
共 0 条评论, 1 页
评论区
写评论还没有评论