Looking at the methods available for Vec<T>
I stumbled across
into_boxed_slice(self) -> Box<[T]>
String
also has such a method (into_boxed_str(self)
). The usefulness of having Deref
for Vec<T>
/String
that allows them to be treated like a shared slice (&[T]
) is obvious, but I don't see any use for an owned slice (Box<[T]>
) except, perhaps, FFI. The Rust GitHub repo only uses into_boxed_slice()
in a handful of cases.
Since methods for creating boxed slices are available in std
and this container is listed on its main page, I thought that I might be missing something useful about it. What are cases where I should use an owned slice in favor of a Vec<T>
or a String
?