Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map store_item: Take item by reference instead of by value #22

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ When using peek_many, you can look at all data from oldest to newest.
(DD-MM-YY)

### Unreleased
- *Breaking* The item to store is now passed by reference to Map `store_item`

### 0.7.0 10-01-24

Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ fn fuzz(ops: Input) {
&mut flash,
FLASH_RANGE,
&mut buf.0,
item.clone(),
&item,
)) {
Ok(_) => {
map.insert(item.key, item.value);
Expand Down
24 changes: 12 additions & 12 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
//! &mut flash,
//! flash_range.clone(),
//! &mut data_buffer,
//! MyCustomType { key: 42, data: 104729 },
//! &MyCustomType { key: 42, data: 104729 },
//! ).await.unwrap();
//!
//! // When we ask for key 42, we not get back a Some with the correct value
Expand Down Expand Up @@ -241,7 +241,7 @@ pub async fn store_item<I: StorageItem, S: NorFlash>(
flash: &mut S,
flash_range: Range<u32>,
data_buffer: &mut [u8],
item: I,
item: &I,
) -> Result<(), MapError<I::Error, S::Error>> {
assert_eq!(flash_range.start % S::ERASE_SIZE as u32, 0);
assert_eq!(flash_range.end % S::ERASE_SIZE as u32, 0);
Expand Down Expand Up @@ -733,7 +733,7 @@ mod tests {
&mut flash,
flash_range.clone(),
&mut data_buffer,
MockStorageItem {
&MockStorageItem {
key: 0,
value: vec![5],
},
Expand All @@ -744,7 +744,7 @@ mod tests {
&mut flash,
flash_range.clone(),
&mut data_buffer,
MockStorageItem {
&MockStorageItem {
key: 0,
value: vec![5, 6],
},
Expand All @@ -764,7 +764,7 @@ mod tests {
&mut flash,
flash_range.clone(),
&mut data_buffer,
MockStorageItem {
&MockStorageItem {
key: 1,
value: vec![2, 2, 2, 2, 2, 2],
},
Expand Down Expand Up @@ -793,7 +793,7 @@ mod tests {
&mut flash,
flash_range.clone(),
&mut data_buffer,
MockStorageItem {
&MockStorageItem {
key: (index % 10) as u8,
value: vec![(index % 10) as u8 * 2; index % 10],
},
Expand Down Expand Up @@ -821,7 +821,7 @@ mod tests {
&mut flash,
flash_range.clone(),
&mut data_buffer,
MockStorageItem {
&MockStorageItem {
key: 11,
value: vec![0; 10],
},
Expand Down Expand Up @@ -864,7 +864,7 @@ mod tests {
};
println!("Storing {item:?}");

store_item::<_, _>(&mut tiny_flash, 0x00..0x40, &mut data_buffer, item)
store_item::<_, _>(&mut tiny_flash, 0x00..0x40, &mut data_buffer, &item)
.await
.unwrap();
}
Expand All @@ -874,7 +874,7 @@ mod tests {
&mut tiny_flash,
0x00..0x40,
&mut data_buffer,
MockStorageItem {
&MockStorageItem {
key: UPPER_BOUND,
value: vec![0; UPPER_BOUND as usize],
},
Expand Down Expand Up @@ -914,7 +914,7 @@ mod tests {
};
println!("Storing {item:?}");

store_item::<_, _>(&mut big_flash, 0x0000..0x1000, &mut data_buffer, item)
store_item::<_, _>(&mut big_flash, 0x0000..0x1000, &mut data_buffer, &item)
.await
.unwrap();
}
Expand All @@ -924,7 +924,7 @@ mod tests {
&mut big_flash,
0x0000..0x1000,
&mut data_buffer,
MockStorageItem {
&MockStorageItem {
key: UPPER_BOUND,
value: vec![0; UPPER_BOUND as usize],
},
Expand Down Expand Up @@ -966,7 +966,7 @@ mod tests {
value: vec![i as u8; LENGHT_PER_KEY[i]],
};

store_item::<_, _>(&mut flash, 0x0000..0x4000, &mut data_buffer, item)
store_item::<_, _>(&mut flash, 0x0000..0x4000, &mut data_buffer, &item)
.await
.unwrap();
}
Expand Down
Loading