It is easy to create a boxed slice:
fn main() {
let _ = Box::new([42, 0]);
}
But if I want to add specify a type:
fn main() {
let _ = Box::<[i32]>::new([42, 0]);
}
I get:
error: no associated item named `new` found for type `std::boxed::Box<[i32]>` in the current scope
--> src/main.rs:2:13
|
2 | let _ = Box::<[i32]>::new([42, 0]);
| ^^^^^^^^^^^^^^^^^
|
= note: the method `new` exists but the following trait bounds were not satisfied: `[i32] : std::marker::Sized`
This is really strange, because it works with type ascription:
fn main() {
let _: Box<[i32]> = Box::new([42, 0]);
}