//! Conversion from [`U512`] into a `[u64; 8]` big-endian limb array.
use super::U512;

/// Converts a [`U512`] into its eight `u64` limbs in big-endian order:
/// `[w0, w1, w2, w3, w4, w5, w6, w7]` where `w0` is the most
/// significant.
///
/// This is the inverse of `From<[u64; 8]> for U512` and equivalent to
/// calling [`U512::to_be_limbs`].
///
/// # Examples
///
/// ```
/// use cnfy_uint::u512::U512;
///
/// let v = U512::from_be_limbs([1, 2, 3, 4, 5, 6, 7, 8]);
/// let arr: [u64; 8] = v.into();
/// assert_eq!(arr, [1, 2, 3, 4, 5, 6, 7, 8]);
/// ```
impl From<U512> for [u64; 8] {
    #[inline]
    fn from(value: U512) -> Self {
        [value.0[7], value.0[6], value.0[5], value.0[4], value.0[3], value.0[2], value.0[1], value.0[0]]
    }
}

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

    /// Round-trip from limbs through U512 back to limbs.
    #[test]
    fn round_trip() {
        let arr = [0xA, 0xB, 0xC, 0xD, 0xE, 0xF, 0x10, 0x11];
        let v = U512::from_be_limbs(arr);
        let back: [u64; 8] = v.into();
        assert_eq!(back, arr);
    }

    /// Zero converts to all-zero limbs.
    #[test]
    fn zero() {
        let arr: [u64; 8] = U512::from_be_limbs([0; 8]).into();
        assert_eq!(arr, [0; 8]);
    }

    /// All-max converts to all-max limbs.
    #[test]
    fn max() {
        let arr: [u64; 8] = U512::from_be_limbs([u64::MAX; 8]).into();
        assert_eq!(arr, [u64::MAX; 8]);
    }
}
