Function array_bytes::vec_n_into

source ·
pub fn vec_n_into<const N: usize, T, V>(vec: Vec<T>) -> Result<V>where
    V: From<[T; N]>,
Expand description

Convert Vec<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::vec_n_into::<17, u8, LJF>(b"Love Jane Forever".to_vec()),
	Ok(LJF(*b"Love Jane Forever"))
);