This commit is contained in:
aozhiwei 2023-10-07 19:14:46 +08:00
parent 687ccf14fa
commit 1a2c64931e

View File

@ -74,11 +74,14 @@ impl<T> ListHead<T> {
head.borrow_mut().init();
}
pub fn for_each(&self, cb: fn () -> i64) {
let pos = self.next.clone();
pub fn for_each(&self, cb: fn (&Weak::<RefCell::<T>>) -> bool) {
let mut pos = self.next.clone();
let self_weak = &Rc::downgrade(&self.get_rc_refcell());
while !Weak::ptr_eq(&pos, self_weak) {
if !cb(&pos.upgrade().unwrap().borrow().data()) {
break;
}
pos = pos.upgrade().unwrap().borrow().next.clone();
}
}