Skip to content

Commit

Permalink
Implement IntoIterator for tags
Browse files Browse the repository at this point in the history
Getting a clippy warning for our into_iter implementation.

Signed-off-by: William Casarin <[email protected]>
  • Loading branch information
jb55 committed Apr 12, 2024
1 parent 0119c5f commit 67796a7
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 }
Expand Down

0 comments on commit 67796a7

Please sign in to comment.