aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib.rs18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 476a094..b0df1ec 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,5 +1,7 @@
extern crate num_traits;
+use std::str::FromStr;
+
use std::fmt::{Debug, Display};
use std::ops::{Add, Sub, AddAssign, SubAssign};
@@ -20,8 +22,10 @@ pub trait Address where Self:
AddAssign + SubAssign +
WrappingAdd + WrappingSub +
CheckedAdd + CheckedSub +
+ FromStr +
identities::One + identities::Zero {
fn to_linear(&self) -> usize;
+
}
/*
impl <T> Address for T where T: Sized + Ord + Add<Output=Self> + From<u16> + Into<usize> {
@@ -29,6 +33,12 @@ impl <T> Address for T where T: Sized + Ord + Add<Output=Self> + From<u16> + Int
}
*/
+impl AddressDisplay for usize {
+ fn stringy(&self) -> String {
+ format!("{:#x}", self)
+ }
+}
+
impl AddressDisplay for u32 {
fn stringy(&self) -> String {
format!("{:#x}", self)
@@ -49,9 +59,13 @@ impl Address for u32 {
fn to_linear(&self) -> usize { *self as usize }
}
+impl Address for usize {
+ fn to_linear(&self) -> usize { *self }
+}
+
pub trait Decodable where Self: Sized {
- fn decode<'a, T: IntoIterator<Item=&'a u8>>(bytes: T) -> Option<Self>;
- fn decode_into<'a, T: IntoIterator<Item=&'a u8>>(&mut self, bytes: T) -> Option<()>;
+ fn decode<T: IntoIterator<Item=u8>>(bytes: T) -> Option<Self>;
+ fn decode_into<T: IntoIterator<Item=u8>>(&mut self, bytes: T) -> Option<()>;
}
pub trait Arch {