From 1a2c64931e9dde5c02662aef4edde975b70f38e6 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 7 Oct 2023 19:14:46 +0800 Subject: [PATCH] 1 --- src/listhead.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/listhead.rs b/src/listhead.rs index a05e6c8..0cac040 100644 --- a/src/listhead.rs +++ b/src/listhead.rs @@ -74,11 +74,14 @@ impl ListHead { 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::>) -> 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(); } }