Skip to content

Commit

Permalink
v0.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mdecimus committed Sep 5, 2023
1 parent b0a5925 commit e5a4e65
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/core/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl<'x> Address<'x> {
}

/// Returns an iterator over the addresses in the list, or the addresses in the groups.
pub fn iter<'y: 'x>(&'y self) -> Box<dyn Iterator<Item = &Addr<'x>> + 'x> {
pub fn iter<'y: 'x>(&'y self) -> Box<dyn DoubleEndedIterator<Item = &Addr<'x>> + 'x> {
match self {
Address::List(list) => Box::new(list.iter()),
Address::Group(group) => {
Expand All @@ -82,6 +82,24 @@ impl<'x> Address<'x> {
}
}

/// Returns whether the list contains the given address.
pub fn contains(&self, addr: &str) -> bool {
match self {
Address::List(list) => list.iter().any(|a| {
a.address
.as_ref()
.map_or(false, |a| a.eq_ignore_ascii_case(addr))
}),
Address::Group(group) => group.iter().any(|group| {
group.addresses.iter().any(|a| {
a.address
.as_ref()
.map_or(false, |a| a.eq_ignore_ascii_case(addr))
})
}),
}
}

pub fn into_owned(self) -> Address<'static> {
match self {
Address::List(list) => {
Expand Down Expand Up @@ -124,4 +142,12 @@ impl<'x> Addr<'x> {
address: self.address.map(|s| s.into_owned().into()),
}
}

pub fn name(&self) -> Option<&str> {
self.name.as_deref()
}

pub fn address(&self) -> Option<&str> {
self.address.as_deref()
}
}

0 comments on commit e5a4e65

Please sign in to comment.