From dab853009fa222bb62ab38f05f4f2d41eaac86c2 Mon Sep 17 00:00:00 2001 From: vms Date: Wed, 21 Oct 2020 16:26:11 +0300 Subject: [PATCH] add deriving more traits for ast types --- src/ast.rs | 21 ++++++++++++--------- src/interpreter/instructions/arrays.rs | 12 ++---------- src/interpreter/instructions/mod.rs | 5 ++++- src/lib.rs | 4 ++-- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index e51559e..1d28ec9 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -5,10 +5,13 @@ use crate::{ interpreter::Instruction, types::{InterfaceType, RecordType}, }; + +use serde::Deserialize; +use serde::Serialize; use std::str; /// Represents the kind of type. -#[derive(PartialEq, Debug, Clone)] +#[derive(PartialEq, Eq, Debug, Clone, Hash, Serialize, Deserialize)] pub enum TypeKind { /// A function type. Function, @@ -18,7 +21,7 @@ pub enum TypeKind { } /// Represents the function argument type. -#[derive(PartialEq, Debug, Clone)] +#[derive(PartialEq, Eq, Debug, Clone, Hash, Serialize, Deserialize)] pub struct FunctionArg { /// A function argument name. pub name: String, @@ -28,7 +31,7 @@ pub struct FunctionArg { } /// Represents a type. -#[derive(PartialEq, Debug, Clone)] +#[derive(PartialEq, Eq, Debug, Clone, Hash, Serialize, Deserialize)] pub enum Type { /// A function type, like: /// @@ -52,7 +55,7 @@ pub enum Type { } /// Represents an imported function. -#[derive(PartialEq, Debug)] +#[derive(PartialEq, Eq, Debug, Default, Clone, Hash)] pub struct Import<'input> { /// The function namespace. pub namespace: &'input str, @@ -65,7 +68,7 @@ pub struct Import<'input> { } /// Represents an exported function signature. -#[derive(PartialEq, Debug)] +#[derive(PartialEq, Eq, Debug, Default, Clone, Hash)] pub struct Export<'input> { /// The export name. pub name: &'input str, @@ -75,7 +78,7 @@ pub struct Export<'input> { } /// Represents an adapter. -#[derive(PartialEq, Debug)] +#[derive(PartialEq, Eq, Debug, Clone, Hash, Serialize, Deserialize)] pub struct Adapter { /// The adapter function type. pub function_type: u32, @@ -85,7 +88,7 @@ pub struct Adapter { } /// Represents an implementation. -#[derive(PartialEq, Debug)] +#[derive(PartialEq, Eq, Debug, Default, Clone, Hash, Serialize, Deserialize)] pub struct Implementation { /// The core function type. pub core_function_type: u32, @@ -95,7 +98,7 @@ pub struct Implementation { } /// Represents the kind of interface. -#[derive(PartialEq, Debug)] +#[derive(PartialEq, Eq, Debug, Clone, Hash, Serialize, Deserialize)] pub(crate) enum InterfaceKind { /// A type. Type, @@ -115,7 +118,7 @@ pub(crate) enum InterfaceKind { /// Represents a set of interfaces, i.e. it entirely describes a WIT /// definition. -#[derive(PartialEq, Default, Debug)] +#[derive(PartialEq, Eq, Debug, Default, Clone, Hash)] pub struct Interfaces<'input> { /// All the types. pub types: Vec, diff --git a/src/interpreter/instructions/arrays.rs b/src/interpreter/instructions/arrays.rs index ee81cba..87198c7 100644 --- a/src/interpreter/instructions/arrays.rs +++ b/src/interpreter/instructions/arrays.rs @@ -140,11 +140,7 @@ where result } InterfaceType::Array(ty) => { - let data = transmute_many::< - u32, - AllOrNothingGuard, - >(&data) - .unwrap(); + let data = transmute_many::(&data).unwrap(); if data.is_empty() { return Ok(vec![]); @@ -186,11 +182,7 @@ where ) })?; - let data = transmute_many::< - u32, - AllOrNothingGuard, - >(&data) - .unwrap(); + let data = transmute_many::(&data).unwrap(); let mut result = Vec::with_capacity(data.len()); diff --git a/src/interpreter/instructions/mod.rs b/src/interpreter/instructions/mod.rs index 6107889..994bfce 100644 --- a/src/interpreter/instructions/mod.rs +++ b/src/interpreter/instructions/mod.rs @@ -26,11 +26,14 @@ pub(crate) use strings::*; pub(crate) use swap2::swap2; pub(self) use utils::*; +use serde::Deserialize; +use serde::Serialize; + pub(self) const ALLOCATE_FUNC_INDEX: u32 = 0; pub(self) const DEALLOCATE_FUNC_INDEX: u32 = 1; /// Represents all the possible WIT instructions. -#[derive(PartialEq, Debug, Clone)] +#[derive(PartialEq, Eq, Debug, Clone, Hash, Serialize, Deserialize)] pub enum Instruction { /// The `arg.get` instruction. ArgumentGet { diff --git a/src/lib.rs b/src/lib.rs index 35623ff..a9eda2f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,8 +39,8 @@ //! [instructions]: interpreter::Instruction #![deny( - // dead_code, - intra_doc_link_resolution_failure, + dead_code, + broken_intra_doc_links, missing_docs, nonstandard_style, unreachable_patterns,