use num_traits::{PrimInt,NumCast,NumOps};
pub struct GameState<T>
where T: PrimInt
{
guess_bounds: GuessBounds<T>,
guess_count: T,
to_guess: T
}
impl<T> GameState<T>
where T: PrimInt
{
pub fn new(guess_bounds: GuessBounds<T>, to_guess: T) -> Self {
GameState { guess_bounds, guess_count:NumCast::from(0).unwrap(), to_guess } //guess_bounds is short for guess_bounds:guess_bounds
}
pub fn process_guess(&mut self, guess: &Guess<T>) -> super::guess::GuessState { //() is unit type aka void (implicit when -> is left out)
self.guess_count = NumOps::add(NumCast::from(self.guess_count).unwrap(), NumCast::from(1).unwrap());
}
}
self.guess_count = NumOps::add(NumCast::from(self.guess_count).unwrap(), NumCast::from(1).unwrap());
| ^^^^^^^^^^^^^ the trait `NumCast` is not implemented for `dyn NumOps<_, _, Output = _, Output = _, Output = _, Output = _, Output = _>`
|
= help: the following other types implement trait `NumCast`:
Wrapping<T>
f32
f64
i128
i16
i32
i64
i8
and 7 others
I've tried many things to simply add a 1 to self.guess_count but cannot figure it out. I am pretty new to generics and traits in general but I'd like to figure this out as it is a good learning opportunity.