summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authordhivael <dhivael.git@eno.space>2017-05-28 04:32:46 +0200
committerdhivael <dhivael.git@eno.space>2017-05-28 04:32:46 +0200
commit4b18f6485ea120d8a006690378e29398646e17fd (patch)
tree6b90b26824c89ab25e3478bfdba84dda9664fee2
parent89dcad42c27c8064a6a3dd13484e2fec1706c974 (diff)
remove duplicated pointer matching
-rw-r--r--src/lib.rs21
1 files changed, 7 insertions, 14 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 6c3b403..33ace3e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -35,9 +35,7 @@ struct IfaddrHandle {
addrs: *mut libc::ifaddrs,
}
-struct IfaddrIter<'a> {
- cur: Option<&'a libc::ifaddrs>,
-}
+struct IfaddrIter<'a>(*const libc::ifaddrs, std::marker::PhantomData<&'a libc::ifaddrs>);
impl IfaddrHandle {
fn new() -> Result<IfaddrHandle, errno::Errno> {
@@ -49,10 +47,7 @@ impl IfaddrHandle {
}
fn iter(&self) -> IfaddrIter {
- match self.addrs as usize {
- 0 => IfaddrIter{ cur: None },
- _ => IfaddrIter{ cur: Some(unsafe { &*self.addrs }) },
- }
+ IfaddrIter(self.addrs, std::marker::PhantomData)
}
}
@@ -66,13 +61,11 @@ impl<'a> Iterator for IfaddrIter<'a> {
type Item = &'a libc::ifaddrs;
fn next(&mut self) -> Option<Self::Item> {
- match self.cur {
- None => None,
- Some(addr) => {
- match addr.ifa_next as usize {
- 0 => self.cur = None,
- _ => self.cur = Some(unsafe { &*addr.ifa_next }),
- }
+ match self.0 as usize {
+ 0 => None,
+ _ => {
+ let addr = unsafe { &*self.0 };
+ self.0 = addr.ifa_next;
Some(addr)
}
}