Skip to main content

ps_ecc/polynomial/implementations/try_from/
byte_array.rs

1use crate::{Polynomial, PolynomialFromSliceError};
2
3impl<const N: usize> TryFrom<[u8; N]> for Polynomial {
4    type Error = PolynomialFromSliceError;
5
6    fn try_from(value: [u8; N]) -> Result<Self, Self::Error> {
7        Self::from_slice(&value)
8    }
9}
10
11impl<const N: usize> TryFrom<&[u8; N]> for Polynomial {
12    type Error = PolynomialFromSliceError;
13
14    fn try_from(value: &[u8; N]) -> Result<Self, Self::Error> {
15        Self::from_slice(value)
16    }
17}
18
19#[cfg(test)]
20#[allow(clippy::expect_used)]
21mod tests {
22    use crate::Polynomial;
23
24    #[test]
25    fn from_array() {
26        let poly = Polynomial::try_from([1, 2, 3]).expect("array should succeed");
27
28        assert_eq!(poly.coefficients(), &[1, 2, 3]);
29    }
30
31    #[test]
32    fn from_array_ref() {
33        let poly = Polynomial::try_from(&[1, 2, 3]).expect("array ref should succeed");
34
35        assert_eq!(poly.coefficients(), &[1, 2, 3]);
36    }
37}