I have an instance of type &T. How do I cast it to &[T; 1]? Something like std::slice::from_ref, except that it should return an array, instead of a slice.
I have an instance of type &T. How do I cast it to &[T; 1]? Something like std::slice::from_ref, except that it should return an array, instead of a slice.
Use array::from_ref or array::from_mut.
fn example(a: &String) -> &[String; 1] {
std::array::from_ref(a)
}
See also: