From f8b14dd92bf97841791e1938394a20aca982689f Mon Sep 17 00:00:00 2001 From: iximeow Date: Sun, 10 Mar 2019 17:28:27 -0700 Subject: tweak core lifetimes, add an address formatter --- src/lib.rs | 18 ++++++++++++++++-- 1 file 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 Address for T where T: Sized + Ord + Add + From + Into { @@ -29,6 +33,12 @@ impl Address for T where T: Sized + Ord + Add + From + 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>(bytes: T) -> Option; - fn decode_into<'a, T: IntoIterator>(&mut self, bytes: T) -> Option<()>; + fn decode>(bytes: T) -> Option; + fn decode_into>(&mut self, bytes: T) -> Option<()>; } pub trait Arch { -- cgit v1.1