Skip to content

Commit

Permalink
feat: derive serde for OpCode, improve implementations (bluealloy#1215)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored and fubuloubu committed Apr 11, 2024
1 parent 1bd27b5 commit b7acb37
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions crates/interpreter/src/instructions/opcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,17 @@ opcodes! {
///
/// This is always a valid opcode, as declared in the [`opcode`][self] module or the
/// [`OPCODE_JUMPMAP`] constant.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(transparent)]
pub struct OpCode(u8);

impl fmt::Debug for OpCode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "OpCode::{self}")
}
}

impl fmt::Display for OpCode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let n = self.get();
Expand Down Expand Up @@ -488,20 +495,6 @@ impl OpCode {
pub const fn get(self) -> u8 {
self.0
}

#[inline]
#[deprecated(note = "use `new` instead")]
#[doc(hidden)]
pub const fn try_from_u8(opcode: u8) -> Option<Self> {
Self::new(opcode)
}

#[inline]
#[deprecated(note = "use `get` instead")]
#[doc(hidden)]
pub const fn u8(self) -> u8 {
self.get()
}
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
Expand Down

0 comments on commit b7acb37

Please sign in to comment.