AsMut
(or BorrowMut
) works:
use std::convert::AsMut;
fn make_array<A, T>(slice: &[T]) -> A
where A: Sized + Default + AsMut<[T]>,
T: Copy
{
let mut a = Default::default();
// the type cannot be inferred!
// a.as_mut().copy_from_slice(slice);
<A as AsMut<[T]>>::as_mut(&mut a).copy_from_slice(slice);
a
}