commit ee256e8c96d76cd05e42a9a85d43c96962e2a5ad
parent 1489a5aee49996d8a6a54b4c3c9c8397e3e8d40f
Author: William Casarin <jb55@jb55.com>
Date:   Fri, 12 Apr 2024 10:46:00 -0700
trait: implement IntoIterator for tags
Getting a clippy warning for our into_iter implementation.
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/src/tags.rs b/src/tags.rs
@@ -15,11 +15,6 @@ impl<'a> Tag<'a> {
         unsafe { bindings::ndb_tag_count(self.as_ptr()) }
     }
 
-    #[inline]
-    pub fn into_iter(self) -> TagIter<'a> {
-        TagIter::new(self)
-    }
-
     pub fn get(&self, ind: u16) -> Option<NdbStr<'a>> {
         if ind >= self.count() {
             return None;
@@ -43,12 +38,30 @@ impl<'a> Tag<'a> {
     }
 }
 
+impl<'a> IntoIterator for Tag<'a> {
+    type Item = NdbStr<'a>;
+    type IntoIter = TagIter<'a>;
+
+    fn into_iter(self) -> Self::IntoIter {
+        TagIter::new(self)
+    }
+}
+
 #[derive(Debug, Copy, Clone)]
 pub struct Tags<'a> {
     ptr: *mut bindings::ndb_tags,
     note: &'a Note<'a>,
 }
 
+impl<'a> IntoIterator for Tags<'a> {
+    type Item = Tag<'a>;
+    type IntoIter = TagsIter<'a>;
+
+    fn into_iter(self) -> Self::IntoIter {
+        TagsIter::new(self.note())
+    }
+}
+
 impl<'a> Tags<'a> {
     pub(crate) fn new(ptr: *mut bindings::ndb_tags, note: &'a Note<'a>) -> Self {
         Tags { ptr, note }