Skip to content

Commit b461f3d

Browse files
committed
Blanket implementation of Region for all types implementing NorFlashRegion
1 parent fbc2268 commit b461f3d

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/lib.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ pub trait NorFlashRegion {
104104
fn erase_sizes(&self) -> Vec<usize, U5>;
105105
}
106106

107+
/// Blanket implementation for all types implementing [`NorFlashRegion`]
108+
impl<T: NorFlashRegion> Region for T {
109+
fn contains(&self, address: Address) -> bool {
110+
let (start, end) = self.range();
111+
address.0 >= start.0 && address.0 < end.0
112+
}
113+
}
114+
107115
/// NOR flash storage trait
108116
pub trait NorFlash {
109117
/// An enumeration of storage errors
@@ -141,11 +149,8 @@ pub trait NorFlash {
141149
/// address range
142150
pub trait UniformNorFlash {}
143151

144-
/// Automatic implementation of region trait for uniform NOR flashes
145-
impl<T> NorFlashRegion for T
146-
where
147-
T: NorFlash + UniformNorFlash,
148-
{
152+
/// Blanket implementation for all types implementing [`NorFlash`] and [`UniformNorFlash`]
153+
impl<T: NorFlash + UniformNorFlash> NorFlashRegion for T {
149154
/// The range of possible addresses within the peripheral.
150155
///
151156
/// (start_addr, end_addr)

0 commit comments

Comments
 (0)