In Rust (like most programming languages), the % operator performs the remainder operation, not the modulus operation. These operations have d
%
From the other answers I constructed:
fn n_mod_m + std::ops::Add + Copy> (n: T, m: T) -> T { ((n % m) + m) % m } assert_eq!(n_mod_m(-21, 4), 3);