mirror of
https://github.com/achanda/ipnetwork.git
synced 2025-06-17 01:08:53 +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 {
|
pub struct Ipv4NetworkIterator {
|
||||||
next: u32,
|
next: u32,
|
||||||
end: 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.
|
/// Converts a `Ipv4Addr` network mask into a prefix.
|
||||||
///
|
///
|
||||||
/// If the mask is invalid this will return an `IpNetworkError::InvalidPrefix`.
|
/// If the mask is invalid this will return an `IpNetworkError::InvalidPrefix`.
|
||||||
|
@ -227,6 +227,7 @@ impl From<Ipv6Addr> for Ipv6Network {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
pub struct Ipv6NetworkIterator {
|
pub struct Ipv6NetworkIterator {
|
||||||
next: u128,
|
next: u128,
|
||||||
end: u128,
|
end: u128,
|
||||||
@ -246,6 +247,14 @@ impl Iterator for Ipv6NetworkIterator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl IntoIterator for &'_ Ipv6Network {
|
||||||
|
type IntoIter = Ipv6NetworkIterator;
|
||||||
|
type Item = Ipv6Addr;
|
||||||
|
fn into_iter(self) -> Ipv6NetworkIterator {
|
||||||
|
self.iter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl fmt::Display for Ipv6Network {
|
impl fmt::Display for Ipv6Network {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(fmt, "{}/{}", self.ip(), self.prefix())
|
write!(fmt, "{}/{}", self.ip(), self.prefix())
|
||||||
|
Reference in New Issue
Block a user