Reputation: 1
I am trying to implement COLA(Cache oblivious look ahead array) in rust using this structure
struct COLA<K: Ord+Copy, V:Clone>{
levels: Vec<Vec<(K,V)>>,
}
My question is how to initialize levels in function fn new()?
I already tried initializing just the outer Vec but I that K,V should be inferred or something similar during creation.
Upvotes: 0
Views: 98
Reputation: 2581
You do only need to initialize the outer Vec, but to get the generic type arguments to follow it down to the method implementations, you need to stick them on the impl block:
impl<K: Ord + Copy, V: Clone> Cola<K, V> {
fn new() -> Self{
Cola::<K, V> {
levels: Vec::new(),
}
}
};
Upvotes: 1