Skip to content

Commit 3b4fc12

Browse files
authored
Convert buffer to slice so user doesn't need unsafe
Convert buffer to slice so user doesn't need `unsafe`
2 parents 5488faf + ca19595 commit 3b4fc12

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ pub trait FlashAlgorithm: Sized + 'static {
4646
/// # Arguments
4747
///
4848
/// * `address` - The start address of the flash page to program.
49-
/// * `size` - Specifies the size of the data buffer.
5049
/// * `data` - The data to be written to the page.
51-
fn program_page(&mut self, address: u32, size: u32, data: *const u8) -> Result<(), ErrorCode>;
50+
fn program_page(&mut self, address: u32, data: &[u8]) -> Result<(), ErrorCode>;
5251
}
5352

5453
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
@@ -140,7 +139,8 @@ macro_rules! algorithm {
140139
return 1;
141140
}
142141
let this = &mut *_ALGO_INSTANCE.as_mut_ptr();
143-
match <$type as FlashAlgorithm>::program_page(this, addr, size, data) {
142+
let data_slice: &[u8] = unsafe { core::slice::from_raw_parts(data, size as usize) };
143+
match <$type as FlashAlgorithm>::program_page(this, addr, data_slice) {
144144
Ok(()) => 0,
145145
Err(e) => e.get(),
146146
}

0 commit comments

Comments
 (0)