Skip to content

Commit

Permalink
Add start() and end() method to the Region trait
Browse files Browse the repository at this point in the history
  • Loading branch information
aurelj committed Jun 14, 2024
1 parent 4618091 commit 2f87032
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 6 additions & 8 deletions embedded-storage-async/src/nor_flash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 6 additions & 8 deletions src/nor_flash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down

0 comments on commit 2f87032

Please sign in to comment.