cnfy-uint 0.2.3

Zero-dependency 256-bit unsigned integer arithmetic for cryptographic applications
Documentation
//! Conversion from `[u64; 4]` into [`U256`] via the [`From`] trait.
use super::U256;

/// Creates a [`U256`] from a four-element `u64` array in big-endian order.
///
/// This is equivalent to [`U256::from_be_limbs`] but available through
/// the standard [`From`] trait for ergonomic conversions.
///
/// # Examples
///
/// ```
/// use cnfy_uint::u256::U256;
///
/// let v: U256 = [0, 0, 0, 42u64].into();
/// assert_eq!(v, U256::from_be_limbs([0, 0, 0, 42]));
/// ```
impl From<[u64; 4]> for U256 {
    #[inline]
    fn from(value: [u64; 4]) -> Self {
        Self::from_be_limbs(value)
    }
}

#[cfg(test)]
mod ai_tests {
    use super::*;

    /// Round-trip from array through U256 back to limbs.
    #[test]
    fn round_trip() {
        let arr = [1u64, 2, 3, 4];
        let v = U256::from(arr);
        assert_eq!(v.to_be_limbs(), arr);
    }

    /// Zero array produces zero value.
    #[test]
    fn zero() {
        assert_eq!(U256::from([0u64; 4]), U256::ZERO);
    }

    /// Matches from_be_limbs behavior.
    #[test]
    fn matches_from_be_limbs() {
        let arr = [0xA, 0xB, 0xC, 0xD];
        assert_eq!(U256::from(arr), U256::from_be_limbs(arr));
    }
}