3 ms·
TryInto is already implemented for slices in 1.47, so `let foo = u16::from_be_bytes(some_slice.try_into().unwrap());` would work before 1.48. This trait wasn't
by antonf 6y ago
TryInto is already implemented for slices in 1.47, so `let foo = u16::from_be_bytes(some_slice.try_into().unwrap());` would work before 1.48.
This trait wasn't implemented for vectors though, so you would have to write `let foo = u16::from_be_bytes(some_vec.to_slice().try_into().unwrap());`.
With new release you can drop `to_slice()` part. Nothing earth-shattering, but makes sense.
- steveklabnik 6y agoAh fun! I missed that. Time to clean up some code...
- est31 6y ago> TryInto is already implemented for slices in 1.47, so `let foo = u16::from_be_bytes(some_slice.try_into().unwrap());` would work before 1.48. Rustdocs say it was 1.36 even? https://doc.rust-lang.org/nightly/std/primitive.array.html#impl-TryFrom%3C%26%27a%20%5BT%5D%3E https://doc.rust-lang.org/nightly/std/primitive.array.html#i...
- antonf 6y agoYeah, by "In 1.47" I mean that as of 1.47 it was already implemented, didn't check since which version.
- devit 6y agoThat doesn't work with non-copyable types.