Function array_bytes::slice_n_into

source ·
pub fn slice_n_into<T, V, const N: usize>(slice: &[T]) -> Result<V>
where T: Copy, V: From<[T; N]>,
Expand description

Convert &[T] to a type directly.

§Examples

#[derive(Debug, PartialEq)]
struct LJF([u8; 17]);
impl From<[u8; 17]> for LJF {
	fn from(array: [u8; 17]) -> Self {
		Self(array)
	}
}

assert_eq!(
	array_bytes::slice_n_into::<u8, LJF, 17>(b"Love Jane Forever"),
	Ok(LJF(*b"Love Jane Forever"))
);