#[SOLVED] Converting a string slice to a slice of 4 bytes
6 messages · Page 1 of 1 (latest)
first use .as_bytes() on the &str to get &[u8]
then use .try_into() on that to convert it to [u8; 4] (and fail if the length is wrong)
Ah thanks a lot. That worked!
[SOLVED] Converting a string slice to a slice of 4 bytes
Note that you can't represent all [u8; 4]s with strings, as strings only support UTF-8 data. If the data can be any possible [u8; 4], you shouldn't turn it into bytes in a string in the first place.