Skip to content

Commit 854b470

Browse files
committed
Formatting
1 parent 990064e commit 854b470

File tree

1 file changed

+84
-84
lines changed

1 file changed

+84
-84
lines changed

src/lib.rs

Lines changed: 84 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -16,140 +16,140 @@ use nb;
1616

1717
/// Trait to check if two entities are bitwise subset of another.
1818
pub trait BitSubset {
19-
/// Check that every '1' bit is a '1' on the right hand side.
20-
fn is_subset_of(&self, rhs: &Self) -> bool;
19+
/// Check that every '1' bit is a '1' on the right hand side.
20+
fn is_subset_of(&self, rhs: &Self) -> bool;
2121
}
2222

2323
/// Blanket implementation of [`BitSubset`] for all arrays of a type implementing [`BitOr`]
2424
impl<T: Copy + Eq + BitOr<Output = T>> BitSubset for [T] {
25-
fn is_subset_of(&self, rhs: &Self) -> bool {
26-
if self.len() > rhs.len() {
27-
false
28-
} else {
29-
self.iter().zip(rhs.iter()).all(|(a, b)| (*a | *b) == *b)
30-
}
31-
}
25+
fn is_subset_of(&self, rhs: &Self) -> bool {
26+
if self.len() > rhs.len() {
27+
false
28+
} else {
29+
self.iter().zip(rhs.iter()).all(|(a, b)| (*a | *b) == *b)
30+
}
31+
}
3232
}
3333

3434
/// An address denotes the read/write address of a single word.
3535
#[derive(Default, Copy, Clone, Debug, PartialOrd, PartialEq, Eq, Ord)]
3636
pub struct Address(pub u32);
3737

3838
impl Add<usize> for Address {
39-
type Output = Self;
39+
type Output = Self;
4040

41-
fn add(self, rhs: usize) -> Self::Output {
42-
Address(self.0 + rhs as u32)
43-
}
41+
fn add(self, rhs: usize) -> Self::Output {
42+
Address(self.0 + rhs as u32)
43+
}
4444
}
4545

4646
impl Add<Address> for Address {
47-
type Output = Self;
47+
type Output = Self;
4848

49-
fn add(self, rhs: Address) -> Self::Output {
50-
Address(self.0 + rhs.0)
51-
}
49+
fn add(self, rhs: Address) -> Self::Output {
50+
Address(self.0 + rhs.0)
51+
}
5252
}
5353

5454
impl Sub<Address> for Address {
55-
type Output = Self;
55+
type Output = Self;
5656

57-
fn sub(self, rhs: Address) -> Self::Output {
58-
Address(self.0 - rhs.0)
59-
}
57+
fn sub(self, rhs: Address) -> Self::Output {
58+
Address(self.0 - rhs.0)
59+
}
6060
}
6161

6262
/// A region denotes a contiguous piece of memory between two addresses.
6363
pub trait Region {
64-
/// Check if `address` is contained in the region of `Self`
65-
fn contains(&self, address: Address) -> bool;
64+
/// Check if `address` is contained in the region of `Self`
65+
fn contains(&self, address: Address) -> bool;
6666
}
6767

6868
/// Iterator producing block-region pairs, where each memory block maps to each
6969
/// region.
7070
pub struct OverlapIterator<'a, R, I>
7171
where
72-
R: Region,
73-
I: Iterator<Item = R>,
72+
R: Region,
73+
I: Iterator<Item = R>,
7474
{
75-
memory: &'a [u8],
76-
regions: I,
77-
base_address: Address,
75+
memory: &'a [u8],
76+
regions: I,
77+
base_address: Address,
7878
}
7979

8080
/// Trait allowing us to automatically add an `overlaps` function to all iterators over [`Region`]
8181
pub trait IterableByOverlaps<'a, R, I>
8282
where
83-
R: Region,
84-
I: Iterator<Item = R>,
83+
R: Region,
84+
I: Iterator<Item = R>,
8585
{
86-
/// Obtain an [`OverlapIterator`] over a subslice of `memory` that overlaps with the region in `self`
87-
fn overlaps(self, memory: &'a [u8], base_address: Address) -> OverlapIterator<R, I>;
86+
/// Obtain an [`OverlapIterator`] over a subslice of `memory` that overlaps with the region in `self`
87+
fn overlaps(self, memory: &'a [u8], base_address: Address) -> OverlapIterator<R, I>;
8888
}
8989

9090
impl<'a, R, I> Iterator for OverlapIterator<'a, R, I>
9191
where
92-
R: Region,
93-
I: Iterator<Item = R>,
92+
R: Region,
93+
I: Iterator<Item = R>,
9494
{
95-
type Item = (&'a [u8], R, Address);
96-
97-
fn next(&mut self) -> Option<Self::Item> {
98-
while let Some(region) = self.regions.next() {
99-
// TODO: This might be possible to do in a smarter way?
100-
let mut block_range = (0..self.memory.len())
101-
.skip_while(|index| !region.contains(self.base_address + Address(*index as u32)))
102-
.take_while(|index| region.contains(self.base_address + Address(*index as u32)));
103-
if let Some(start) = block_range.next() {
104-
let end = block_range.last().unwrap_or(start) + 1;
105-
return Some((
106-
&self.memory[start..end],
107-
region,
108-
self.base_address + Address(start as u32),
109-
));
110-
}
111-
}
112-
None
113-
}
95+
type Item = (&'a [u8], R, Address);
96+
97+
fn next(&mut self) -> Option<Self::Item> {
98+
while let Some(region) = self.regions.next() {
99+
// TODO: This might be possible to do in a smarter way?
100+
let mut block_range = (0..self.memory.len())
101+
.skip_while(|index| !region.contains(self.base_address + Address(*index as u32)))
102+
.take_while(|index| region.contains(self.base_address + Address(*index as u32)));
103+
if let Some(start) = block_range.next() {
104+
let end = block_range.last().unwrap_or(start) + 1;
105+
return Some((
106+
&self.memory[start..end],
107+
region,
108+
self.base_address + Address(start as u32),
109+
));
110+
}
111+
}
112+
None
113+
}
114114
}
115115

116116
/// Blanket implementation for all types implementing [`Iterator`] over [`Regions`]
117117
impl<'a, R, I> IterableByOverlaps<'a, R, I> for I
118118
where
119-
R: Region,
120-
I: Iterator<Item = R>,
119+
R: Region,
120+
I: Iterator<Item = R>,
121121
{
122-
fn overlaps(self, memory: &'a [u8], base_address: Address) -> OverlapIterator<R, I> {
123-
OverlapIterator {
124-
memory,
125-
regions: self,
126-
base_address,
127-
}
128-
}
122+
fn overlaps(self, memory: &'a [u8], base_address: Address) -> OverlapIterator<R, I> {
123+
OverlapIterator {
124+
memory,
125+
regions: self,
126+
base_address,
127+
}
128+
}
129129
}
130130

131131
/// Storage trait
132132
pub trait ReadWrite {
133-
/// An enumeration of storage errors
134-
type Error;
135-
136-
/// Read a slice of data from the storage peripheral, starting the read
137-
/// operation at the given address, and reading until end address
138-
/// (`self.range().1`) or buffer length, whichever comes first.
139-
fn try_read(&mut self, address: Address, bytes: &mut [u8]) -> nb::Result<(), Self::Error>;
140-
141-
/// Write a slice of data to the storage peripheral, starting the write
142-
/// operation at the given address.
143-
fn try_write(&mut self, address: Address, bytes: &[u8]) -> nb::Result<(), Self::Error>;
144-
145-
/// The range of possible addresses within the peripheral.
146-
///
147-
/// (start_addr, end_addr)
148-
fn range(&self) -> (Address, Address);
149-
150-
/// Erase the given storage range, clearing all data within `[from..to]`.
151-
///
152-
/// This should return an error if the range is not aligned to a proper
153-
/// erase resolution
154-
fn try_erase(&mut self, from: Address, to: Address) -> nb::Result<(), Self::Error>;
133+
/// An enumeration of storage errors
134+
type Error;
135+
136+
/// Read a slice of data from the storage peripheral, starting the read
137+
/// operation at the given address, and reading until end address
138+
/// (`self.range().1`) or buffer length, whichever comes first.
139+
fn try_read(&mut self, address: Address, bytes: &mut [u8]) -> nb::Result<(), Self::Error>;
140+
141+
/// Write a slice of data to the storage peripheral, starting the write
142+
/// operation at the given address.
143+
fn try_write(&mut self, address: Address, bytes: &[u8]) -> nb::Result<(), Self::Error>;
144+
145+
/// The range of possible addresses within the peripheral.
146+
///
147+
/// (start_addr, end_addr)
148+
fn range(&self) -> (Address, Address);
149+
150+
/// Erase the given storage range, clearing all data within `[from..to]`.
151+
///
152+
/// This should return an error if the range is not aligned to a proper
153+
/// erase resolution
154+
fn try_erase(&mut self, from: Address, to: Address) -> nb::Result<(), Self::Error>;
155155
}

0 commit comments

Comments
 (0)