Skip to content

Commit c1d56a6

Browse files
committed
refactor: clippy and fmt
Signed-off-by: addrian-77 <lunguadrian30@gmail.com>
1 parent 7e6cc90 commit c1d56a6

6 files changed

Lines changed: 66 additions & 36 deletions

File tree

tockloader-cli/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ use tockloader_lib::connection::{
1818
use tockloader_lib::known_boards::KnownBoard;
1919
use tockloader_lib::tabs::tab::Tab;
2020
use tockloader_lib::{
21-
list_debug_probes, list_serial_ports, CommandDisableApp, CommandEnableApp, CommandInfo, CommandInstall, CommandList
21+
list_debug_probes, list_serial_ports, CommandDisableApp, CommandEnableApp, CommandInfo,
22+
CommandInstall, CommandList,
2223
};
2324

2425
fn get_serial_target_info(user_options: &ArgMatches) -> SerialTargetInfo {

tockloader-lib/src/command_impl/generalized.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::board_settings::BoardSettings;
66
use crate::connection::TockloaderConnection;
77
use crate::errors::TockloaderError;
88
use crate::tabs::tab::Tab;
9-
use crate::{CommandInfo, CommandInstall, CommandList, CommandEnableApp, CommandDisableApp};
9+
use crate::{CommandDisableApp, CommandEnableApp, CommandInfo, CommandInstall, CommandList};
1010

1111
#[async_trait]
1212
impl CommandList for TockloaderConnection {
@@ -75,4 +75,3 @@ impl CommandDisableApp for TockloaderConnection {
7575
}
7676
}
7777
}
78-

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

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::CommandDisableApp;
1111

1212
const ENABLED_OFFSET: u64 = 8;
1313
const CHECKSUM_OFFSET: u64 = 12;
14-
14+
1515
#[async_trait]
1616
impl CommandDisableApp for ProbeRSConnection {
1717
async fn disable_app(
@@ -23,7 +23,8 @@ impl CommandDisableApp for ProbeRSConnection {
2323
return Err(InternalError::ConnectionNotOpen.into());
2424
}
2525
let session = self.session.as_mut().expect("Board must be open");
26-
'outer: loop { // this loop is labeled so we can exit early if the app is already disabled
26+
'outer: loop {
27+
// this loop is labeled so we can exit early if the app is already disabled
2728
let mut installed_apps: Vec<AppData> = Vec::new();
2829
let mut index: u8 = 1;
2930
let mut appaddr: u64 = settings.start_address;
@@ -76,9 +77,13 @@ impl CommandDisableApp for ProbeRSConnection {
7677
address: appaddr,
7778
name: pname,
7879
size: app_size,
79-
checksum: u32::from_ne_bytes(header_data[CHECKSUM_OFFSET as usize..CHECKSUM_OFFSET as usize + 4].try_into().unwrap()),
80+
checksum: u32::from_ne_bytes(
81+
header_data[CHECKSUM_OFFSET as usize..CHECKSUM_OFFSET as usize + 4]
82+
.try_into()
83+
.unwrap(),
84+
),
8085
index,
81-
enabled: if header_data[ENABLED_OFFSET as usize] == 1 { true } else { false },
86+
enabled: header_data[ENABLED_OFFSET as usize] == 1,
8287
});
8388
// log::info!("found checksum {:?}", (installed_apps[index as usize].checksum).to_ne_bytes());
8489
// log::info!("changing checksum will result in {:?}", (installed_apps[index as usize].checksum - 1).to_ne_bytes());
@@ -99,7 +104,10 @@ impl CommandDisableApp for ProbeRSConnection {
99104
let mut app: &AppData;
100105
match app_name {
101106
Some(app_name) => {
102-
app = match installed_apps.iter().find(|iter| iter.name == app_name && iter.enabled == true) {
107+
app = match installed_apps
108+
.iter()
109+
.find(|iter| iter.name == app_name && iter.enabled)
110+
{
103111
Some(app) => app,
104112
None => break,
105113
}
@@ -121,32 +129,39 @@ impl CommandDisableApp for ProbeRSConnection {
121129
.unwrap()
122130
== "Confirm"
123131
{
124-
if app.enabled == false {
132+
if !app.enabled {
125133
println!("App is already disabled!");
126-
break 'outer; // exit from the big loop, we don't have to do anything else
134+
break 'outer; // exit from the big loop, we don't have to do anything else
127135
}
128-
break
136+
break;
129137
}
130138
},
131139
}
132140
let mut loader = session.target().flash_loader();
133-
if app.index == 0 { // ALL
141+
if app.index == 0 {
142+
// ALL
134143
// log::info!("ALL");
135144
for app_iter in installed_apps[1..].iter() {
136145
// log::info!("checking app {}", app_iter.name);
137-
if app_iter.enabled == true {
146+
if app_iter.enabled {
138147
// log::info!("entered here????");
139148
loader.add_data(app_iter.address + ENABLED_OFFSET, &[0x0])?;
140-
loader.add_data(app_iter.address + CHECKSUM_OFFSET, &(app_iter.checksum - 1).to_ne_bytes())?; // the checksum must be increased or we'll invalidate the header
149+
loader.add_data(
150+
app_iter.address + CHECKSUM_OFFSET,
151+
&(app_iter.checksum - 1).to_ne_bytes(),
152+
)?; // the checksum must be increased or we'll invalidate the header
141153
}
142154
}
143-
}
144-
else { // only one
155+
} else {
156+
// only one
145157
loader.add_data(app.address + ENABLED_OFFSET, &[0x0])?;
146-
loader.add_data(app.address + CHECKSUM_OFFSET, &(app.checksum - 1).to_ne_bytes())?; // the checksum must be increased or we'll invalidate the header
158+
loader.add_data(
159+
app.address + CHECKSUM_OFFSET,
160+
&(app.checksum - 1).to_ne_bytes(),
161+
)?; // the checksum must be increased or we'll invalidate the header
147162
}
148163
let mut options = DownloadOptions::default();
149-
options.keep_unwritten_bytes = true;
164+
options.keep_unwritten_bytes = true;
150165
loader.commit(session, options)?;
151166

152167
if app_name.is_none() {

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

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ impl CommandEnableApp for ProbeRSConnection {
2323
return Err(InternalError::ConnectionNotOpen.into());
2424
}
2525
let session = self.session.as_mut().expect("Board must be open");
26-
'outer: loop { // this loop is labeled so we can exit early if the app is already enabled
26+
'outer: loop {
27+
// this loop is labeled so we can exit early if the app is already enabled
2728
let mut installed_apps: Vec<AppData> = Vec::new();
2829
let mut index: u8 = 1;
2930
let mut appaddr: u64 = settings.start_address;
@@ -76,9 +77,13 @@ impl CommandEnableApp for ProbeRSConnection {
7677
address: appaddr,
7778
name: pname,
7879
size: app_size,
79-
checksum: u32::from_ne_bytes(header_data[CHECKSUM_OFFSET as usize..CHECKSUM_OFFSET as usize + 4].try_into().unwrap()),
80+
checksum: u32::from_ne_bytes(
81+
header_data[CHECKSUM_OFFSET as usize..CHECKSUM_OFFSET as usize + 4]
82+
.try_into()
83+
.unwrap(),
84+
),
8085
index,
81-
enabled: if header_data[ENABLED_OFFSET as usize] == 1 { true } else { false },
86+
enabled: header_data[ENABLED_OFFSET as usize] == 1,
8287
});
8388
// log::info!("found checksum {:?}", (installed_apps[index as usize].checksum).to_ne_bytes());
8489
// log::info!("changing checksum will result in {:?}", (installed_apps[index as usize].checksum + 1).to_ne_bytes());
@@ -99,7 +104,10 @@ impl CommandEnableApp for ProbeRSConnection {
99104
let mut app: &AppData;
100105
match app_name {
101106
Some(app_name) => {
102-
app = match installed_apps.iter().find(|iter| iter.name == app_name && iter.enabled == false) {
107+
app = match installed_apps
108+
.iter()
109+
.find(|iter| iter.name == app_name && !iter.enabled)
110+
{
103111
Some(app) => app,
104112
None => break,
105113
}
@@ -121,31 +129,38 @@ impl CommandEnableApp for ProbeRSConnection {
121129
.unwrap()
122130
== "Confirm"
123131
{
124-
if app.enabled == true {
132+
if app.enabled {
125133
println!("App is already enabled!");
126-
break 'outer; // just exit
134+
break 'outer; // just exit
127135
}
128-
break
136+
break;
129137
}
130138
},
131139
}
132-
140+
133141
let mut loader = session.target().flash_loader();
134-
135-
if app.index == 0 { // ALL
142+
143+
if app.index == 0 {
144+
// ALL
136145
// log::info!("ALL");
137146
for app_iter in installed_apps[1..].iter() {
138147
// log::info!("checking app {}", app_iter.name);
139-
if app_iter.enabled == false {
148+
if !app_iter.enabled {
140149
// log::info!("entered here????");
141150
loader.add_data(app_iter.address + ENABLED_OFFSET, &[0x1])?;
142-
loader.add_data(app_iter.address + CHECKSUM_OFFSET, &(app_iter.checksum + 1).to_ne_bytes())?; // the checksum must be increased or we'll invalidate the header
151+
loader.add_data(
152+
app_iter.address + CHECKSUM_OFFSET,
153+
&(app_iter.checksum + 1).to_ne_bytes(),
154+
)?; // the checksum must be increased or we'll invalidate the header
143155
}
144156
}
145-
}
146-
else { // only one
157+
} else {
158+
// only one
147159
loader.add_data(app.address + ENABLED_OFFSET, &[0x1])?;
148-
loader.add_data(app.address + CHECKSUM_OFFSET, &(app.checksum + 1).to_ne_bytes())?; // the checksum must be increased or we'll invalidate the header
160+
loader.add_data(
161+
app.address + CHECKSUM_OFFSET,
162+
&(app.checksum + 1).to_ne_bytes(),
163+
)?; // the checksum must be increased or we'll invalidate the header
149164
}
150165
let mut options = DownloadOptions::default();
151166
options.keep_unwritten_bytes = true;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
pub mod disable_app;
2+
pub mod enable_app;
13
pub mod info;
24
pub mod install;
35
pub mod list;
4-
pub mod enable_app;
5-
pub mod disable_app;

tockloader-lib/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,4 @@ pub trait CommandDisableApp {
7676
settings: &BoardSettings,
7777
app_name: Option<&str>,
7878
) -> Result<(), TockloaderError>;
79-
}
79+
}

0 commit comments

Comments
 (0)