Cannot return a vector slice - ops::Range is not implemented

后端 未结 2 1408
野的像风
野的像风 2021-01-13 09:19

Why does the following Rust code give an error?

fn getVecSlice(vec: &Vec, start: i32, len: i32) -> &[f64] {
    vec[start..start + len]         


        
2条回答
  •  醉梦人生
    2021-01-13 09:51

    Why do we need usize:

    usize gives you the guarantee to be always big enough to hold any pointer or any offset in a data structure, while u32 can be too small on some architectures.

    As an example, on a 32 bit x86 computer, usize = u32, while on x86_64 computers, usize = u64.

提交回复
热议问题