Skip to content

Commit

Permalink
added eq, partialeq trait for operator equality comparison (#1652)
Browse files Browse the repository at this point in the history
* added eq, partialeq trait for operator equality comparison

* implemented eq for br table
  • Loading branch information
thesuhas authored Jul 8, 2024
1 parent 1f8e7e2 commit ccbe057
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions crates/wasmparser/src/readers/core/operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub enum BlockType {
}

/// Represents a memory immediate in a WebAssembly memory instruction.
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct MemArg {
/// Alignment, stored as `n` where the actual alignment is `2^n`
pub align: u8,
Expand Down Expand Up @@ -64,6 +64,16 @@ pub struct BrTable<'a> {
pub(crate) default: u32,
}

impl PartialEq<Self> for BrTable<'_> {
fn eq(&self, other: &Self) -> bool {
self.cnt == other.cnt
&& self.default == other.default
&& self.reader.remaining_buffer() == other.reader.remaining_buffer()
}
}

impl Eq for BrTable<'_> {}

/// An IEEE binary32 immediate floating point value, represented as a u32
/// containing the bit pattern.
///
Expand Down Expand Up @@ -155,7 +165,7 @@ macro_rules! define_operator {
/// Instructions as defined [here].
///
/// [here]: https://webassembly.github.io/spec/core/binary/instructions.html
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq, PartialEq)]
#[allow(missing_docs)]
pub enum Operator<'a> {
$(
Expand Down Expand Up @@ -397,7 +407,7 @@ impl<'a, V: VisitOperator<'a> + ?Sized> VisitOperator<'a> for Box<V> {
}

/// A `try_table` entries representation.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct TryTable {
/// The block type describing the try block itself.
pub ty: BlockType,
Expand All @@ -406,7 +416,7 @@ pub struct TryTable {
}

/// Catch clauses that can be specified in [`TryTable`].
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[allow(missing_docs)]
pub enum Catch {
/// Equivalent of `catch`
Expand Down

0 comments on commit ccbe057

Please sign in to comment.