From c5021c15a8a16d789711c8043562b5f52f607642 Mon Sep 17 00:00:00 2001 From: iximeow Date: Thu, 28 Nov 2019 02:19:43 -0800 Subject: decoders are stateful, so decode functions should take them as a parameter --- src/lib.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index b9f416c..c8996ee 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -159,22 +159,24 @@ impl Address for usize { fn to_linear(&self) -> usize { *self } } -pub trait Decodable where Self: Sized { - fn decode>(bytes: T) -> Option; - fn decode_into>(&mut self, bytes: T) -> Option<()>; +pub trait Decoder where Inst: Sized { + fn decode>(&self, bytes: T) -> Option; + fn decode_into>(&self, &mut Inst, bytes: T) -> Option<()>; } #[cfg(feature="use-serde")] pub trait Arch { type Address: Address + Debug + Hash + PartialEq + Eq + Serialize + for<'de> Deserialize<'de>; - type Instruction: Decodable + LengthedInstruction + Debug; + type Instruction: LengthedInstruction + Debug; + type Decoder: Decoder + Default; type Operand; } #[cfg(not(feature="use-serde"))] pub trait Arch { type Address: Address + Debug + Hash + PartialEq + Eq; - type Instruction: Decodable + LengthedInstruction + Debug; + type Instruction: LengthedInstruction + Debug; + type Decoder: Decoder + Default; type Operand; } -- cgit v1.1