Skip to content

Commit

Permalink
fix conversion impls
Browse files Browse the repository at this point in the history
  • Loading branch information
tjjfvi committed Apr 10, 2024
1 parent a579aca commit b8ec277
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -195,15 +196,15 @@ impl TryFrom<u16> for TypedOp {
type Error = ();

fn try_from(value: u16) -> Result<Self, Self::Error> {
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)? })
}
}

impl From<TypedOp> 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])
}
}

Expand Down

0 comments on commit b8ec277

Please sign in to comment.