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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With