Skip to content

Commit f6cd01f

Browse files
committed
refactor: change vec to slice inside write function
Signed-off-by: addrian-77 <lunguadrian30@gmail.com>
1 parent 26e5438 commit f6cd01f

6 files changed

Lines changed: 8 additions & 8 deletions

File tree

tockloader-lib/src/command_impl/erase_apps.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{CommandEraseApps, IO};
77
#[async_trait]
88
impl CommandEraseApps for TockloaderConnection {
99
async fn erase_apps(&mut self) -> Result<(), TockloaderError> {
10-
self.write(self.get_settings().start_address, vec![0u8])
10+
self.write(self.get_settings().start_address, &[0u8])
1111
.await
1212
}
1313
}

tockloader-lib/src/command_impl/generalized.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl IO for TockloaderConnection {
1515
}
1616
}
1717

18-
async fn write(&mut self, address: u64, pkt: Vec<u8>) -> Result<(), TockloaderError> {
18+
async fn write(&mut self, address: u64, pkt: &[u8]) -> Result<(), TockloaderError> {
1919
match self {
2020
TockloaderConnection::ProbeRS(conn) => conn.write(address, pkt).await,
2121
TockloaderConnection::Serial(conn) => conn.write(address, pkt).await,

tockloader-lib/src/command_impl/install.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl CommandInstall for TockloaderConnection {
4646
let pkt = create_pkt(configuration, app_binaries);
4747

4848
// write the pkt
49-
let _ = self.write(self.get_settings().start_address, pkt).await;
49+
let _ = self.write(self.get_settings().start_address, &pkt).await;
5050
Ok(())
5151
}
5252
}

tockloader-lib/src/command_impl/probers/io.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ impl IO for ProbeRSConnection {
2222
Ok(appdata)
2323
}
2424

25-
async fn write(&mut self, address: u64, pkt: Vec<u8>) -> Result<(), TockloaderError> {
25+
async fn write(&mut self, address: u64, pkt: &[u8]) -> Result<(), TockloaderError> {
2626
if !self.is_open() {
2727
return Err(InternalError::ConnectionNotOpen.into());
2828
}
2929
let session = self.session.as_mut().expect("Board must be open");
3030
let mut loader = session.target().flash_loader();
3131

32-
loader.add_data(address, &pkt)?;
32+
loader.add_data(address, pkt)?;
3333

3434
let mut options = DownloadOptions::default();
3535
options.keep_unwritten_bytes = true;

tockloader-lib/src/command_impl/serial/io.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ impl IO for SerialConnection {
3636
Ok(appdata)
3737
}
3838

39-
async fn write(&mut self, address: u64, pkt: Vec<u8>) -> Result<(), TockloaderError> {
39+
async fn write(&mut self, address: u64, pkt: &[u8]) -> Result<(), TockloaderError> {
4040
let settings = self.get_settings();
4141
let stream = self.stream.as_mut().expect("Board must be open");
42-
let mut binary = pkt.clone();
42+
let mut binary = pkt.to_vec();
4343

4444
if !binary.len().is_multiple_of(settings.page_size as usize) {
4545
binary.extend(vec![

tockloader-lib/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub trait CommandEraseApps {
5959
pub trait IO: Send {
6060
async fn read(&mut self, address: u64, size: usize) -> Result<Vec<u8>, TockloaderError>;
6161

62-
async fn write(&mut self, address: u64, pkt: Vec<u8>) -> Result<(), TockloaderError>;
62+
async fn write(&mut self, address: u64, pkt: &[u8]) -> Result<(), TockloaderError>;
6363
}
6464

6565
#[async_trait]

0 commit comments

Comments
 (0)