Hey all, I ran into a case recently where I had a Rust function that wanted a slice reference, but I had a Vec
, and just to be cheeky, I tried dereferencing the Vec
and the function accepted it just fine:
// The function
fn update(buffer: &[u32]) { ... }
// My object
let mut buffer: Vec<u32> = ...;
// Nice, it just works :)
update(&buffer);
This is rad, but I'm a bit confused at how this actually works. What specific types/traits/functions/etc were involved to get from type &Vec<T>
to &[u32]
?