diff --git a/src/ast.rs b/src/ast.rs index 2f5c5b8..8a78221 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -1,4 +1,4 @@ -use std::{convert::TryFrom, str}; +use std::str; #[derive(PartialEq, Debug)] pub enum InterfaceType { @@ -15,26 +15,6 @@ pub enum InterfaceType { AnyRef, } -impl TryFrom for InterfaceType { - type Error = &'static str; - - fn try_from(code: u64) -> Result { - Ok(match code { - 0x7fff => Self::Int, - 0x7ffe => Self::Float, - 0x7ffd => Self::Any, - 0x7ffc => Self::String, - 0x7ffb => Self::Seq, - 0x7f => Self::I32, - 0x7e => Self::I64, - 0x7d => Self::F32, - 0x7c => Self::F64, - 0x6f => Self::AnyRef, - _ => return Err("Unknown interface type code."), - }) - } -} - #[derive(PartialEq, Debug)] pub(crate) enum AdapterKind { Import, @@ -42,19 +22,6 @@ pub(crate) enum AdapterKind { HelperFunction, } -impl TryFrom for AdapterKind { - type Error = &'static str; - - fn try_from(code: u8) -> Result { - Ok(match code { - 0x0 => Self::Import, - 0x1 => Self::Export, - 0x2 => Self::HelperFunction, - _ => return Err("Unknown adapter kind code."), - }) - } -} - #[derive(PartialEq, Debug)] pub enum Instruction<'input> { ArgumentGet(u64), diff --git a/src/parsers.rs b/src/decoders/binary.rs similarity index 95% rename from src/parsers.rs rename to src/decoders/binary.rs index 9d88ab1..614b7b8 100644 --- a/src/parsers.rs +++ b/src/decoders/binary.rs @@ -5,6 +5,39 @@ use nom::{ }; use std::{convert::TryFrom, str}; +impl TryFrom for InterfaceType { + type Error = &'static str; + + fn try_from(code: u64) -> Result { + Ok(match code { + 0x7fff => Self::Int, + 0x7ffe => Self::Float, + 0x7ffd => Self::Any, + 0x7ffc => Self::String, + 0x7ffb => Self::Seq, + 0x7f => Self::I32, + 0x7e => Self::I64, + 0x7d => Self::F32, + 0x7c => Self::F64, + 0x6f => Self::AnyRef, + _ => return Err("Unknown interface type code."), + }) + } +} + +impl TryFrom for AdapterKind { + type Error = &'static str; + + fn try_from(code: u8) -> Result { + Ok(match code { + 0x0 => Self::Import, + 0x1 => Self::Export, + 0x2 => Self::HelperFunction, + _ => return Err("Unknown adapter kind code."), + }) + } +} + fn byte<'input, E: ParseError<&'input [u8]>>(input: &'input [u8]) -> IResult<&'input [u8], u8, E> { if input.is_empty() { return Err(Err::Error(make_error(input, ErrorKind::Eof)));