Expanded form of try_into?

Hi, experts. Code that works:

use std::convert::TryInto;

fn foo<const N: usize>(buffer: &[u8]) -> Result<&[u8;N], std::array::TryFromSliceError> {
    buffer.try_into()
}

fn bar<const N: usize>(buffer: &[u8]) -> Result<&[u8;N], std::array::TryFromSliceError> {
    TryInto::try_into(buffer)
}

What's the expanded form that includes the types, &[u8] and &[u8;N], explicitly?

Thanks in advance.

<&[u8] as TryInto<&[u8; N]>>::try_into(buffer)
2 Likes

Big thanks.
It's so simple and obvious.
How foolish of me.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.