1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
use std::fmt::Display;
use std::ops::Rem;
use num_traits::{AsPrimitive, Zero};
use crate::{InputType, InputValueError};
pub fn multiple_of<T, N>(value: &T, n: N) -> Result<(), InputValueError<T>>
where
T: AsPrimitive<N> + InputType,
N: Rem<Output = N> + Zero + Display + Copy + PartialEq + 'static,
{
if value.as_() % n == N::zero() {
Ok(())
} else {
Err(format!("the value must be a multiple of {}.", n).into())
}
}