aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2019-03-10 17:28:27 -0700
committeriximeow <me@iximeow.net>2020-01-12 16:26:39 -0800
commitf8b14dd92bf97841791e1938394a20aca982689f (patch)
tree3e5d05dea73c455aa875ba0ded020816e0d414c8 /src/lib.rs
parent7b6bdb989ca2204b288db8675d3066074556dfb1 (diff)
tweak core lifetimes, add an address formatter
Diffstat (limited to 'src/lib.rs')
-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 {