mirror of
https://github.com/achanda/ipnetwork.git
synced 2025-06-17 09:18:51 +00:00
Make the iterators slightly better
* Implement some useful traits on them. * Make reference an into-iterator.
This commit is contained in:
@ -253,6 +253,7 @@ impl From<Ipv4Addr> for Ipv4Network {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Ipv4NetworkIterator {
|
||||
next: u32,
|
||||
end: u32,
|
||||
@ -272,6 +273,14 @@ impl Iterator for Ipv4NetworkIterator {
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoIterator for &'_ Ipv4Network {
|
||||
type IntoIter = Ipv4NetworkIterator;
|
||||
type Item = Ipv4Addr;
|
||||
fn into_iter(self) -> Ipv4NetworkIterator {
|
||||
self.iter()
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts a `Ipv4Addr` network mask into a prefix.
|
||||
///
|
||||
/// If the mask is invalid this will return an `IpNetworkError::InvalidPrefix`.
|
||||
|
Reference in New Issue
Block a user