aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2019-11-28 02:19:43 -0800
committeriximeow <me@iximeow.net>2020-01-12 16:26:39 -0800
commitc5021c15a8a16d789711c8043562b5f52f607642 (patch)
treeb4a4f36a0bdbd76f33a05e97effd018dca58c3dd /src/lib.rs
parent312a5a75025b5cb01b9b626822cab3a65e23fafc (diff)
decoders are stateful, so decode functions should take them as a parameter
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs12
1 files changed, 7 insertions, 5 deletions
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<T: IntoIterator<Item=u8>>(bytes: T) -> Option<Self>;
- fn decode_into<T: IntoIterator<Item=u8>>(&mut self, bytes: T) -> Option<()>;
+pub trait Decoder<Inst> where Inst: Sized {
+ fn decode<T: IntoIterator<Item=u8>>(&self, bytes: T) -> Option<Inst>;
+ fn decode_into<T: IntoIterator<Item=u8>>(&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<Unit=Self::Address> + Debug;
+ type Instruction: LengthedInstruction<Unit=Self::Address> + Debug;
+ type Decoder: Decoder<Self::Instruction> + Default;
type Operand;
}
#[cfg(not(feature="use-serde"))]
pub trait Arch {
type Address: Address + Debug + Hash + PartialEq + Eq;
- type Instruction: Decodable + LengthedInstruction<Unit=Self::Address> + Debug;
+ type Instruction: LengthedInstruction<Unit=Self::Address> + Debug;
+ type Decoder: Decoder<Self::Instruction> + Default;
type Operand;
}