diff options
author | SoniEx2 <endermoneymod@gmail.com> | 2022-04-26 11:46:50 -0300 |
---|---|---|
committer | SoniEx2 <endermoneymod@gmail.com> | 2022-04-26 11:46:50 -0300 |
commit | 073e7e952fbbb94ef4c4a69107f1f348496ac123 (patch) | |
tree | 3c0efb1be79a6e0e95680fe03060d2cb86b99953 /src | |
parent | 890546163f06b6389f68fd4d974112440d299ef1 (diff) |
Maybe fix lists not working
Diffstat (limited to 'src')
-rw-r--r-- | src/list.rs | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/list.rs b/src/list.rs index 2f1f93c..5d40e5a 100644 --- a/src/list.rs +++ b/src/list.rs @@ -56,7 +56,7 @@ pub struct Entries<'a, 'ph, T> { pub(crate) context: &'a crate::PluginHandle<'ph>, pub(crate) list: *mut crate::internals::HexchatList, pub(crate) t: &'a T, - pub(crate) valid: Rc<Cell<usize>>, + pub(crate) valid: Option<Rc<Cell<usize>>>, } /// Fields. @@ -99,7 +99,9 @@ impl List for Users { impl<'a, 'ph, T> Drop for Entries<'a, 'ph, T> { fn drop(&mut self) { let ph = &self.context; - self.valid.set(usize::MAX); + if let Some(ref valid) = self.valid { + valid.set(usize::MAX); + } unsafe { ph_call!(hexchat_list_free(ph, self.list)); } @@ -111,21 +113,30 @@ impl<'a, 'ph, T> Iterator for Entries<'a, 'ph, T> { fn next(&mut self) -> Option<Self::Item> { let ph = &self.context; - let id = self.valid.get(); if unsafe { ph_call!(hexchat_list_next(ph, self.list)) } != 0 { - debug_assert!(self.valid.get() < usize::MAX); - self.valid.set(id + 1); + let valid = if let Some(ref valid) = self.valid { + debug_assert!(valid.get() < usize::MAX); + valid.set(valid.get() + 1); + Rc::clone(valid) + } else { + let valid: Rc<Cell<usize>> = Default::default(); + self.valid = Some(Rc::clone(&valid)); + valid + }; + let id = valid.get(); Some(Fields { context: self.context, list: self.list, _t: self.t, - valid: Rc::clone(&self.valid), + valid: valid, id: id, }) } else { - self.valid.set(usize::MAX); + if let Some(ref valid) = self.valid { + valid.set(usize::MAX); + } None } } |