Start using Option::is_none_or

This commit is contained in:
MoskalykA 2024-10-07 06:46:01 +02:00 committed by Laurențiu Nicola
parent 26d2fbaef2
commit 41fa877362
3 changed files with 3 additions and 20 deletions

View file

@ -304,22 +304,6 @@ pub fn slice_tails<T>(this: &[T]) -> impl Iterator<Item = &[T]> {
(0..this.len()).map(|i| &this[i..])
}
pub trait IsNoneOr {
type Type;
#[allow(clippy::wrong_self_convention)]
fn is_none_or(self, s: impl FnOnce(Self::Type) -> bool) -> bool;
}
#[allow(unstable_name_collisions)]
impl<T> IsNoneOr for Option<T> {
type Type = T;
fn is_none_or(self, f: impl FnOnce(T) -> bool) -> bool {
match self {
Some(v) => f(v),
None => true,
}
}
}
#[cfg(test)]
mod tests {
use super::*;