I have some problems with a generic implementation of a method:
use std::collections::BTreeMap;
use global::entity::EntityId;
struct simple_system<T> {
list_sum: BTreeMap<EntityId, T>,
list_com: BTreeMap<EntityId, Vec<T>>,
}
impl<T> simple_system<T> {
pub fn new() -> simple_system<T> {
simple_system {
list_sum: BTreeMap::new(),
list_com: BTreeMap::new(),
}
}
pub fn addComponent(&mut self, id: EntityId, comp: T) {
self.list_com.entry(id).or_insert_with(Vec::new).push(comp);
match self.list_sum.get_mut(&id) {
Some(v) => *v = *v + *comp,
None => self.list_sum.insert(id, comp),
}
}
}
with the following errors.
error[E0614]: type `T` cannot be dereferenced
--> src/main.rs:20:34
|
20 | Some(v) => *v = *v + *comp,
| ^^^^^
error[E0369]: binary operation `+` cannot be applied to type `T`
--> src/main.rs:20:29
|
20 | Some(v) => *v = *v + *comp,
| ^^^^^^^^^^
|
= note: an implementation of `std::ops::Add` might be missing for `T`
I don't know what I have to change to get it to work. I use it with u32
type so it should have an +
operator.