fn main() { let data = &[1..3]; println!("data {:?}", data); } what mean have &[1..3] assigned value statement?
firstly:
let foo = &[1,2,3]; creates temporary array same lifetime foo binding, , stores reference in foo.
however, that's not program doing. other answer says, it's useful run it, , get:
data [1..3] that doesn't [1,2,3]! can trick compiler telling using error messages. know it's not (), let's try first:
fn main() { let data = &[1..3]; let () = data; } this gives error on purpose includes:
error: mismatched types [--explain e0308] --> <anon>:3:17 |> 3 |> let () = data; |> ^^ expected &-ptr, found () note: expected type `&[std::ops::range<_>; 1]` note: found type `()` and tells answer - data reference (&) array of 1 item ([_;1]), std::ops::range<_> object.
Comments
Post a Comment