diff --git a/CHANGELOG.md b/CHANGELOG.md index 2995c02..7824090 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## Unreleased -No unreleased changes yet +- Add `start()` and `end()` method to the `Region` trait. ## [0.3.1] - 2023-12-04 diff --git a/embedded-storage-async/src/nor_flash.rs b/embedded-storage-async/src/nor_flash.rs index d868640..8a2d7b8 100644 --- a/embedded-storage-async/src/nor_flash.rs +++ b/embedded-storage-async/src/nor_flash.rs @@ -102,17 +102,15 @@ impl Page { size, } } - - /// The end address of the page - const fn end(&self) -> u32 { - self.start + self.size as u32 - } } impl Region for Page { - /// Checks if an address offset is contained within the page - fn contains(&self, address: u32) -> bool { - (self.start <= address) && (self.end() > address) + fn start(&self) -> u32 { + self.start + } + + fn end(&self) -> u32 { + self.start + self.size as u32 } } diff --git a/src/lib.rs b/src/lib.rs index 7c5366a..3070723 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,8 +15,16 @@ pub mod nor_flash; /// A region denotes a contiguous piece of memory between two addresses. pub trait Region { + /// Start address of the region of `Self` + fn start(&self) -> u32; + + /// End address of the region of `Self` + fn end(&self) -> u32; + /// Check if `address` is contained in the region of `Self` - fn contains(&self, address: u32) -> bool; + fn contains(&self, address: u32) -> bool { + (address >= self.start()) && (address < self.end()) + } } /// Transparent read only storage trait diff --git a/src/nor_flash.rs b/src/nor_flash.rs index 447bd1a..c20ddba 100644 --- a/src/nor_flash.rs +++ b/src/nor_flash.rs @@ -202,17 +202,15 @@ impl Page { size, } } - - /// The end address of the page - const fn end(&self) -> u32 { - self.start + self.size as u32 - } } impl Region for Page { - /// Checks if an address offset is contained within the page - fn contains(&self, address: u32) -> bool { - (self.start <= address) && (self.end() > address) + fn start(&self) -> u32 { + self.start + } + + fn end(&self) -> u32 { + self.start + self.size as u32 } }