pub trait Integer: Number + Hashable + Ord { }
Expand description
The intersection of Number
types and Hashable
types.
This happens to be integers.
Examples: u8, u16, u32, u64, u128, i8, i16, i32, i64, i128, usize
This trait lists many traits that are implemented for integer types. It is a shorthand to provide broad integer functionality to a generic type, without polluting trait bounds with a large number of highly-specific traits.
Refer to the constituent traits to see proof definitions on methods.
Example
use opendp::traits::Integer;
use std::collections::HashSet;
fn test_func<T: Integer>(value: T) {
// can be debugged
println!("{value:?}");
// supports arithmetic and has numerical properties
assert_eq!(T::zero().inf_mul(&value).ok(), Some(T::zero()));
// can be used in hash sets and in the keys of hashmaps:
let mut hashset = HashSet::new();
hashset.insert(value);
}
test_func(1i8);