File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -71,7 +71,8 @@ pub trait MemoryAddress:
71
71
+ BitOr < Output = Self :: RAW >
72
72
+ BitXor < Output = Self :: RAW >
73
73
+ Debug
74
- + From < u8 > ;
74
+ + From < u8 >
75
+ + TryInto < usize , Error : Debug > ;
75
76
76
77
/// Get the raw underlying address value.
77
78
fn raw ( self ) -> Self :: RAW ;
@@ -97,8 +98,10 @@ impl fmt::Display for AddrRangeError {
97
98
98
99
/// A memory range.
99
100
pub struct AddrRange < T : MemoryAddress > {
100
- start : T ,
101
- end : T ,
101
+ /// Starting address
102
+ pub start : T ,
103
+ /// End address (exclusive)
104
+ pub end : T ,
102
105
}
103
106
impl < T : MemoryAddress > AddrRange < T > {
104
107
/// Construct a new memory range from `start` (inclusive) to `end` (exclusive).
@@ -121,6 +124,15 @@ impl<T: MemoryAddress> AddrRange<T> {
121
124
pub fn contains ( & self , element : & T ) -> bool {
122
125
element. raw ( ) >= self . start . raw ( ) && element. raw ( ) < self . end . raw ( )
123
126
}
127
+
128
+ /// Amount of addresses in the range.
129
+ ///
130
+ /// `AddrRange`s are half open, so the range from `0x0` to `0x1` has length 1.
131
+ pub fn length ( & self ) -> usize {
132
+ ( self . end . raw ( ) - self . start . raw ( ) )
133
+ . try_into ( )
134
+ . expect ( "address range is larger than the architecture's usize" )
135
+ }
124
136
}
125
137
126
138
/// An iterator over a memory range
You can’t perform that action at this time.
0 commit comments