Relative Content

Tag Archive for genericsrusttraits

How to enforce generic parameter to be of type u8, u16, u32, or u64 in Rust?

I’m trying to write a function in Rust that should accept a generic parameter T, but I want to enforce T to be one of the unsigned integer types (u8, u16, u32, or u64). Additionally, I want to restrict T to support certain bitwise operations such as AND (&) and OR (|), as well as bitwise assignment operators (&= and |=).

Assignment and copy of BigUint in generics

I would like to write code for unsigned integer (and later maybe signed integer) no matter their type. So the way to go is to use generic types and implementing the super trait “Unsigned”. But I have a problem with BigUint.
Here is a basic code for an extended euclid algorithm.