summary refs log tree commit diff stats
path: root/src
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
parent073e7e952fbbb94ef4c4a69107f1f348496ac123 (diff)
Wait for streaming/lending iterators.
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs6
-rw-r--r--src/list.rs34
2 files changed, 5 insertions, 35 deletions
diff --git a/src/lib.rs b/src/lib.rs
index cf04809..8f72571 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -379,8 +379,6 @@ mod valid_context {
                     // available through get_info.
                     list: ptr::null_mut(),
                     _t: &CONTEXTS,
-                    id: 0,
-                    valid: Default::default(),
                 },
                 _hidden: (),
             }
@@ -1569,7 +1567,8 @@ impl<'a, 'ph: 'a> ValidContext<'a, 'ph> {
     /// 
     /// fn print_contexts(ph: &mut PluginHandle<'_>) {
     ///     ph.ensure_valid_context(|ph| {
-    ///         for context in ph.list(&Contexts) {
+    ///         let mut contexts = ph.list(&Contexts);
+    ///         while let Some(context) = contexts.next() {
     ///             write!(ph, "{}", context.name().unwrap());
     ///         }
     ///     })
@@ -1585,7 +1584,6 @@ impl<'a, 'ph: 'a> ValidContext<'a, 'ph> {
             context: self.ph,
             list: list,
             t: t,
-            valid: Default::default(),
         }
     }
 
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(