array_bytes

Function vec_n_into

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

Convert Vec<T> to V where V: From<[T; N]>.

ยง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::<u8, Ljf, 17>(b"Love Jane Forever".to_vec()),
	Ok(Ljf(*b"Love Jane Forever"))
);