Merge pull request #347 from vadorovsky/fix-lint

bpf: Use `then_some` instead of `then(|| [...])`
pull/346/head
Michal Rostecki 2 years ago committed by GitHub
commit f08bb022f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -47,7 +47,7 @@ impl<T> BloomFilter<T> {
value as *const _ as *mut c_void,
)
};
(ret == 0).then(|| ()).ok_or(ret)
(ret == 0).then_some(()).ok_or(ret)
}
#[inline]
@ -59,7 +59,7 @@ impl<T> BloomFilter<T> {
flags,
)
};
(ret == 0).then(|| ()).ok_or(ret)
(ret == 0).then_some(()).ok_or(ret)
}
}

@ -348,11 +348,11 @@ fn insert<K, V>(def: *mut bpf_map_def, key: &K, value: &V, flags: u64) -> Result
flags,
)
};
(ret == 0).then(|| ()).ok_or(ret)
(ret == 0).then_some(()).ok_or(ret)
}
#[inline]
fn remove<K>(def: *mut bpf_map_def, key: &K) -> Result<(), c_long> {
let ret = unsafe { bpf_map_delete_elem(def as *mut _, key as *const _ as *const c_void) };
(ret == 0).then(|| ()).ok_or(ret)
(ret == 0).then_some(()).ok_or(ret)
}

@ -78,7 +78,7 @@ impl<K, V> LpmTrie<K, V> {
flags,
)
};
(ret == 0).then(|| ()).ok_or(ret)
(ret == 0).then_some(()).ok_or(ret)
}
#[inline]
@ -86,7 +86,7 @@ impl<K, V> LpmTrie<K, V> {
let ret = unsafe {
bpf_map_delete_elem(self.def.get() as *mut _, key as *const _ as *const c_void)
};
(ret == 0).then(|| ()).ok_or(ret)
(ret == 0).then_some(()).ok_or(ret)
}
}

@ -53,14 +53,14 @@ impl<T> Queue<T> {
flags,
)
};
(ret == 0).then(|| ()).ok_or(ret)
(ret == 0).then_some(()).ok_or(ret)
}
pub fn pop(&self) -> Option<T> {
unsafe {
let mut value = mem::MaybeUninit::uninit();
let ret = bpf_map_pop_elem(self.def.get() as *mut _, value.as_mut_ptr() as *mut _);
(ret == 0).then(|| value.assume_init())
(ret == 0).then_some(value.assume_init())
}
}
}

@ -61,7 +61,7 @@ impl<K> SockHash<K> {
flags,
)
};
(ret == 0).then(|| ()).ok_or(ret)
(ret == 0).then_some(()).ok_or(ret)
}
pub fn redirect_msg(&self, ctx: &SkMsgContext, key: &mut K, flags: u64) -> i64 {
@ -102,7 +102,7 @@ impl<K> SockHash<K> {
}
let ret = bpf_sk_assign(ctx.as_ptr() as *mut _, sk, flags);
bpf_sk_release(sk);
(ret == 0).then(|| ()).ok_or(1)
(ret == 0).then_some(()).ok_or(1)
}
}
}

@ -102,7 +102,7 @@ impl SockMap {
}
let ret = bpf_sk_assign(ctx.as_ptr() as *mut _, sk, flags);
bpf_sk_release(sk);
(ret == 0).then(|| ()).ok_or(1)
(ret == 0).then_some(()).ok_or(1)
}
}
}

@ -51,7 +51,7 @@ impl<T> Stack<T> {
flags,
)
};
(ret == 0).then(|| ()).ok_or(ret)
(ret == 0).then_some(()).ok_or(ret)
}
pub fn pop(&mut self) -> Option<T> {
@ -61,7 +61,7 @@ impl<T> Stack<T> {
&mut self.def as *mut _ as *mut _,
value.as_mut_ptr() as *mut _,
);
(ret == 0).then(|| value.assume_init())
(ret == 0).then_some(value.assume_init())
}
}
}

Loading…
Cancel
Save