#[repr(transparent)]
#[derive(Copy, Debug)]
#[derive_const(
Clone,
Eq,
Ord,
PartialEq,
PartialOrd,
)]
pub struct Instruction([u16; 5]);
impl Instruction {
pub const MAX_LEN: usize = 5;
pub const NOP: Self = Self::from_slice(&[0b0100111001110001]);
#[inline]
#[must_use]
pub const fn from_slice(s: &[u16]) -> Self {
let words = match *s {
[word0, word1, word2, word3, word4, ..] => {
[word0, word1, word2, word3, word4]
}
[word0, word1, word2, word3] => {
[word0, word1, word2, word3, 0]
}
[word0, word1, word2] => {
[word0, word1, word2, 0, 0]
}
[word0, word1] => {
[word0, word1, 0, 0, 0]
}
[word0] => {
[word0, 0, 0, 0, 0]
}
[] => {
[0, 0, 0, 0, 0]
}
};
Self(words)
}
#[expect(clippy::len_without_is_empty)]
#[must_use]
pub const fn len(self) -> usize {
todo!();
}
#[inline]
#[must_use]
pub const fn as_ne_bytes(self) -> [u8; 10] {
let [word0, word1, word2, word3, word4] = self.0;
let [byte0, byte1] = word0.to_ne_bytes();
let [byte2, byte3] = word1.to_ne_bytes();
let [byte4, byte5] = word2.to_ne_bytes();
let [byte6, byte7] = word3.to_ne_bytes();
let [byte8, byte9] = word4.to_ne_bytes();
[
byte0, byte1, byte2, byte3, byte4, byte5, byte6, byte7,
byte8, byte9,
]
}
}
const impl Default for Instruction {
#[inline(always)]
fn default() -> Self {
Self::NOP
}
}