I am trying to create a struct in Rust that is itself generic with respect to other generic structs. That's pretty confusing so hopefully this example will makes things clearer:
use std::ops::Deref;
use std::rc::Rc;
struct Foo<T: Deref> {
val: T<i32>,
other: i32,
}
impl<T> Foo<T> {
pub fn new(&self, val: T<i32>, other: i32) -> Self {
Foo {val: val, other: other}
}
}
fn main() {
let foo = Foo::new(Rc::new(0), 0);
}
I would like to be able to create a Foo object by calling new with either Rc<i32> objects or Arc<i32> objects depending on whether I need thread safety or not. I get the following error when I try this though: error[E0109]: type parameters are not allowed on this type, as the compiler complains about the i32 in val: T<i32>,. Is this possible in Rust? If so, can I safely call methods on i32 assuming it will auto dereference it?