cnfy-uint 0.2.3

Zero-dependency 256-bit unsigned integer arithmetic for cryptographic applications
Documentation
//! Conversion from `u64` into [`U320`].
use super::U320;

/// Creates a [`U320`] from a `u64` value, placing it in the least
/// significant limb with the upper four limbs set to zero.
///
/// # Examples
///
/// ```
/// use cnfy_uint::u320::U320;
///
/// let v = U320::from(42u64);
/// assert_eq!(v, U320::from_be_limbs([0, 0, 0, 0, 42]));
/// ```
impl From<u64> for U320 {
    #[inline]
    fn from(value: u64) -> Self {
        Self::from_be_limbs([0, 0, 0, 0, value])
    }
}

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

    /// Converting zero produces U320::ZERO.
    #[test]
    fn zero() {
        assert_eq!(U320::from(0u64), U320::ZERO);
    }

    /// Converting one produces U320::ONE.
    #[test]
    fn one() {
        assert_eq!(U320::from(1u64), U320::ONE);
    }

    /// Converting u64::MAX fills only the lowest limb.
    #[test]
    fn max_u64() {
        assert_eq!(
            U320::from(u64::MAX),
            U320::from_be_limbs([0, 0, 0, 0, u64::MAX]),
        );
    }

    /// Arbitrary value round-trips through to_be_limbs.
    #[test]
    fn round_trip() {
        let v = U320::from(0xDEADBEEFu64);
        assert_eq!(v.to_be_limbs(), [0, 0, 0, 0, 0xDEADBEEF]);
    }
}