summary refs log tree commit diff stats
path: root/src/list.rs
diff options
context:
space:
mode:
authorSoniEx2 <endermoneymod@gmail.com>2022-04-26 22:43:57 -0300
committerSoniEx2 <endermoneymod@gmail.com>2022-04-26 22:43:57 -0300
commitb5b6d25d6ad1473128697e3c3bf09b441a65c359 (patch)
tree763f71427e4fa4d961c23dd256fdf99b31ad7c2a /src/list.rs
parent073e7e952fbbb94ef4c4a69107f1f348496ac123 (diff)
Wait for streaming/lending iterators.
Diffstat (limited to 'src/list.rs')
-rw-r--r--src/list.rs34
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(