Skip to content

Commit e5a4e65

Browse files
committed
v0.9.0
1 parent b0a5925 commit e5a4e65

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/core/address.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl<'x> Address<'x> {
7373
}
7474

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

85+
/// Returns whether the list contains the given address.
86+
pub fn contains(&self, addr: &str) -> bool {
87+
match self {
88+
Address::List(list) => list.iter().any(|a| {
89+
a.address
90+
.as_ref()
91+
.map_or(false, |a| a.eq_ignore_ascii_case(addr))
92+
}),
93+
Address::Group(group) => group.iter().any(|group| {
94+
group.addresses.iter().any(|a| {
95+
a.address
96+
.as_ref()
97+
.map_or(false, |a| a.eq_ignore_ascii_case(addr))
98+
})
99+
}),
100+
}
101+
}
102+
85103
pub fn into_owned(self) -> Address<'static> {
86104
match self {
87105
Address::List(list) => {
@@ -124,4 +142,12 @@ impl<'x> Addr<'x> {
124142
address: self.address.map(|s| s.into_owned().into()),
125143
}
126144
}
145+
146+
pub fn name(&self) -> Option<&str> {
147+
self.name.as_deref()
148+
}
149+
150+
pub fn address(&self) -> Option<&str> {
151+
self.address.as_deref()
152+
}
127153
}

0 commit comments

Comments
 (0)