I'm working on a generic struct that's supposed to support all the standard integer types. As a part of the struct there's a configurable upper limit. I want to set that upper limit during construction to the integer type's maximum value.
It was suggested to me that the num crate (well, specifically the num-traits crate) could help me bound the generic type to integer types.
I have something along the lines of:
use num_traits as num;
struct Ids<T> {
limit: T
}
impl<T: Sized + num::Bounded> Ids<T> {
fn new() -> Result<Self, Error> {
Ids { limit: T::max_value() }
}
When I compile that it tells me that it expects an integer for limit
, but it found "type parameter T
" (in new()
).
Is my assumption about that I should be able to do that wrong, or have I just not understood the syntax?