pub struct Arr<T> {
v: Vec<T>,
p: u16,
s: u16,
l: usize,
}
impl<T> Arr<T> {
pub fn new(length: usize) -> Arr<T> {
let mut vec = Vec::<T>::with_capacity(length);
let mut i = 0;
while i<length {
let mut zero = 0 as T
vec.push(zero);
i++
}
return Arr {
v: vec,
p: 0,
s: 0,
l: length,
}
}
}
Now it says I have error... near 0 as T
= note: expected type parameter `T`
found type `{integer}`
I just want to get floating types 0 float, and integer types 0 integer, but it seems somehow tricky to me. How do you fill vector with it's respective type?
Tto be constrained to only numeric types? or is zero supposed to work for non-numerics as well?