use std::fmt::Debug;
use num::Zero;
fn main() {
let i: i32 = 7;
is_working(i);
}
fn is_working<T>(l: T)
where
T: Debug + Zero + std::cmp::PartialEq,
{
if l == 0 {
println!("{:#?}", ("great"));
}
}
The is_zero method is found relatively easily, on the page of the Zero trait. The other method (zero) is also found there, and it's important to notice that it is a static method: it doesn't take a self. So you can call it on the type as T::zero().
I believe the zero could also have been defined as an associated constant on the trait, in that case it would have been e.g. T::ZERO.
Indeed, or even T::_0. Nowadays, with const generics, we could even imagine a fully general <T as Get<0>>::VALUE. Another approach being to have From<U0> (or From<_0> if renamed), with U0 being a type-level equivalent of 0, such as ::typenum::U0 or U::<0> for some struct U<const N: u32>;. Many possibilites