I am trying to implement TryFrom for converting a string to a slice with the help of the following code shown below.
impl<const N: usize> TryFrom<String> for [u8; N] {
type Error = &'static str;
fn try_from(value: String) -> Result<[u8; N], Self::Error> {
let val = value.as_bytes()[..];
Ok(val)
}
}
I am getting a compilation error when I call
let a = String::try_from("a".to_string())
impl<const N: usize> TryFrom<String> for [u8; N] {
| ^^^^^^^^^^^^^^^^^^^^^---------------^^^^^-------
| | | |
| | | this is not defined in the current crate because arrays are always foreign
| | `std::string::String` is not defined in the current crate
| impl doesn't use only types from inside the current crate