From b8ec27751761fa9aec4e43830a2c5e1f2d67dcbc Mon Sep 17 00:00:00 2001 From: tjjfvi Date: Wed, 10 Apr 2024 10:08:25 -0400 Subject: [PATCH] fix conversion impls --- src/ops.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ops.rs b/src/ops.rs index 302c3ce5..98a47357 100644 --- a/src/ops.rs +++ b/src/ops.rs @@ -135,6 +135,7 @@ impl Op { /// A numeric operator. #[repr(C)] #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[repr(align(2))] pub struct TypedOp { /// The type of the operands. pub ty: Ty, @@ -195,7 +196,7 @@ impl TryFrom for TypedOp { type Error = (); fn try_from(value: u16) -> Result { - let [ty, op] = value.to_be_bytes(); + let [ty, op] = value.to_ne_bytes(); Ok(Self { ty: Ty::try_from(ty)?, op: Op::try_from(op)? }) } @@ -203,7 +204,7 @@ impl TryFrom for TypedOp { impl From for u16 { fn from(TypedOp { ty, op }: TypedOp) -> Self { - ((ty as u16) << 8) | (op as u16) + u16::from_ne_bytes([ty as u8, op as u8]) } }