aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2019-04-21 14:16:44 -0700
committeriximeow <me@iximeow.net>2020-01-12 16:26:39 -0800
commitcd2881ff02ae5c90bf459581df9dcdef1535ab23 (patch)
tree9ff33787099656a342a033509b19bfbb07312d19
parent9e2e1a1bc0f0a03e03a6e370ce91536bc2443774 (diff)
awful tweaks to expose a serde flag on yaxpeax-arch which will trickle through everything
-rw-r--r--Cargo.toml8
-rw-r--r--src/lib.rs29
2 files changed, 37 insertions, 0 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 005384f..3436931 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -10,6 +10,14 @@ description = "fundamental traits to describe an architecture in the yaxpeax pro
[dependencies]
"num-traits" = "0.2"
"termion" = "1.4.0"
+"serde" = "*"
[profile.release]
lto = true
+
+[features]
+default = []
+
+# enables the (optional) use of Serde for bounds on
+# Arch and Arch::Address
+use-serde = []
diff --git a/src/lib.rs b/src/lib.rs
index b62d52f..8f98366 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,5 +1,7 @@
extern crate num_traits;
extern crate termion;
+#[cfg(feature="use-serde")]
+extern crate serde;
use std::str::FromStr;
@@ -14,6 +16,9 @@ use num_traits::{Bounded, WrappingAdd, WrappingSub, CheckedAdd, CheckedSub};
use termion::color;
+#[cfg(feature="use-serde")]
+use serde::{Serialize, Deserialize};
+
pub mod display;
// This is pretty wonk..
pub trait AddressDisplay {
@@ -34,6 +39,22 @@ pub trait AddrParse: Sized {
fn parse_from(s: &str) -> Result<Self, Self::Err>;
}
+#[cfg(feature="use-serde")]
+pub trait Address where Self:
+ Serialize + for<'de> Deserialize<'de> +
+ Debug + Display + AddressDisplay +
+ Copy + Clone + Sized +
+ Ord + Eq + PartialEq + Bounded +
+ Add<Output=Self> + Sub<Output=Self> +
+ AddAssign + SubAssign +
+ WrappingAdd + WrappingSub +
+ CheckedAdd + CheckedSub +
+ AddrParse +
+ identities::One + identities::Zero {
+ fn to_linear(&self) -> usize;
+
+}
+#[cfg(not(feature="use-serde"))]
pub trait Address where Self:
Debug + Display + AddressDisplay +
Copy + Clone + Sized +
@@ -142,6 +163,14 @@ pub trait Decodable where Self: Sized {
fn decode_into<T: IntoIterator<Item=u8>>(&mut self, bytes: T) -> Option<()>;
}
+#[cfg(feature="use-serde")]
+pub trait Arch {
+ type Address: Address + Debug + Serialize + for<'de> Deserialize<'de>;
+ type Instruction: Decodable + LengthedInstruction<Unit=Self::Address> + Debug;
+ type Operand;
+}
+
+#[cfg(not(feature="use-serde"))]
pub trait Arch {
type Address: Address + Debug;
type Instruction: Decodable + LengthedInstruction<Unit=Self::Address> + Debug;