From 67796a7841db32e1c5160cef3878666d8bfe935a Mon Sep 17 00:00:00 2001 From: William Casarin Date: Fri, 12 Apr 2024 10:46:00 -0700 Subject: [PATCH] Implement IntoIterator for tags Getting a clippy warning for our into_iter implementation. Signed-off-by: William Casarin --- src/tags.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/tags.rs b/src/tags.rs index eb9c21f..cc1c58d 100644 --- 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> { 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 }