diff options
Diffstat (limited to 'src/list.rs')
-rw-r--r-- | src/list.rs | 34 |
1 files changed, 3 insertions, 31 deletions
diff --git a/src/list.rs b/src/list.rs index 5d40e5a..e6d4aaa 100644 --- a/src/list.rs +++ b/src/list.rs @@ -17,9 +17,7 @@ //! List support module. use std::borrow::Cow; -use std::cell::Cell; use std::ffi::CStr; -use std::rc::Rc; use crate::Context; use crate::wrap_context; @@ -56,7 +54,6 @@ 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: Option<Rc<Cell<usize>>>, } /// Fields. @@ -64,8 +61,6 @@ pub struct Fields<'a, 'ph, T> { pub(crate) context: &'a crate::PluginHandle<'ph>, pub(crate) list: *mut crate::internals::HexchatList, pub(crate) _t: &'a T, - pub(crate) id: usize, - pub(crate) valid: Rc<Cell<usize>>, } // impls @@ -99,44 +94,25 @@ impl List for Users { impl<'a, 'ph, T> Drop for Entries<'a, 'ph, T> { fn drop(&mut self) { let ph = &self.context; - if let Some(ref valid) = self.valid { - valid.set(usize::MAX); - } unsafe { ph_call!(hexchat_list_free(ph, self.list)); } } } -impl<'a, 'ph, T> Iterator for Entries<'a, 'ph, T> { - type Item = Fields<'a, 'ph, T>; - - fn next(&mut self) -> Option<Self::Item> { +impl<'a, 'ph, T> Entries<'a, 'ph, T> { + /// Returns the next entry on the list, if any. + pub fn next<'b>(&'b mut self) -> Option<Fields<'b, 'ph, T>> where 'a: 'b { let ph = &self.context; if unsafe { ph_call!(hexchat_list_next(ph, self.list)) } != 0 { - 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: valid, - id: id, }) } else { - if let Some(ref valid) = self.valid { - valid.set(usize::MAX); - } None } } @@ -145,10 +121,6 @@ impl<'a, 'ph, T> Iterator for Entries<'a, 'ph, T> { macro_rules! field { ($(#[$m:meta])* $f:ident, unsafe {$n:expr}, $r:ty, $ph:ident, $c:ident, $($conv:tt)+) => { $(#[$m])* pub fn $f(&self) -> $r { - assert_eq!( - self.id, self.valid.get(), - "instances of Fields are invalidated by next()", - ); let $ph = &self.context; const NAME: &'static CStr = unsafe { CStr::from_bytes_with_nul_unchecked( |