Add possibility to use enum Instruction in hash structures

This commit is contained in:
C.Solovev 2018-12-15 23:54:58 +04:00
parent e586a7ac87
commit c7c2d1f246
3 changed files with 15 additions and 4 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ Cargo.lock
.vscode
**/.DS_Store
rls
.idea

View File

@ -104,7 +104,7 @@ impl Deserialize for InitExpr {
}
/// Instruction.
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[allow(missing_docs)]
pub enum Instruction {
Unreachable,
@ -539,14 +539,14 @@ pub enum Instruction {
TableCopy,
}
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[allow(missing_docs)]
pub struct MemArg {
pub align: u8,
pub offset: u32,
}
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[allow(missing_docs)]
pub struct BrTableData {
pub table: Box<[u32]>,
@ -2780,3 +2780,13 @@ fn display() {
fn size_off() {
assert!(::std::mem::size_of::<Instruction>() <= 24);
}
#[test]
fn instructions_hashset() {
use self::Instruction::{Call, Block, Drop};
use super::types::{BlockType::Value, ValueType};
let set: std::collections::HashSet<Instruction> =
vec![Call(1), Block(Value(ValueType::I32)), Drop].into_iter().collect();
assert_eq!(set.contains(&Drop), true)
}

View File

@ -92,7 +92,7 @@ impl fmt::Display for ValueType {
}
/// Block type which is basically `ValueType` + NoResult (to define blocks that have no return type)
#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum BlockType {
/// Value-type specified block type
Value(ValueType),