0
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?

MniNi
  • 35
  • 3
  • 3
    do you want `T` to be constrained to only numeric types? or is zero supposed to work for non-numerics as well? – kmdreko Jun 10 '20 at 22:01
  • See also: https://stackoverflow.com/questions/28565440/how-do-i-use-integer-number-literals-when-using-generic-types – E_net4 Jun 10 '20 at 22:10

0 Answers0