Skip to content

Commit f855272

Browse files
committed
Fix issues reported by clippy
Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
1 parent 7209f14 commit f855272

File tree

10 files changed

+27
-122
lines changed

10 files changed

+27
-122
lines changed

libosdp/src/commands.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,7 @@ impl From<libosdp_sys::osdp_cmd_text> for OsdpCommandText {
280280
impl From<OsdpCommandText> for libosdp_sys::osdp_cmd_text {
281281
fn from(value: OsdpCommandText) -> Self {
282282
let mut data = [0; libosdp_sys::OSDP_CMD_TEXT_MAX_LEN as usize];
283-
for i in 0..value.data.len() {
284-
data[i] = value.data[i];
285-
}
283+
data[..value.data.len()].copy_from_slice(&value.data[..]);
286284
libosdp_sys::osdp_cmd_text {
287285
reader: value.reader,
288286
control_code: value.control_code,
@@ -414,9 +412,7 @@ impl From<libosdp_sys::osdp_cmd_keyset> for OsdpCommandKeyset {
414412
impl From<OsdpCommandKeyset> for libosdp_sys::osdp_cmd_keyset {
415413
fn from(value: OsdpCommandKeyset) -> Self {
416414
let mut data = [0; libosdp_sys::OSDP_CMD_KEYSET_KEY_MAX_LEN as usize];
417-
for i in 0..value.data.len() {
418-
data[i] = value.data[i];
419-
}
415+
data[..value.data.len()].copy_from_slice(&value.data[..]);
420416
libosdp_sys::osdp_cmd_keyset {
421417
type_: value.key_type,
422418
length: value.data.len() as u8,
@@ -455,9 +451,7 @@ impl From<libosdp_sys::osdp_cmd_mfg> for OsdpCommandMfg {
455451
impl From<OsdpCommandMfg> for libosdp_sys::osdp_cmd_mfg {
456452
fn from(value: OsdpCommandMfg) -> Self {
457453
let mut data = [0; libosdp_sys::OSDP_CMD_MFG_MAX_DATALEN as usize];
458-
for i in 0..value.data.len() {
459-
data[i] = value.data[i];
460-
}
454+
data[..value.data.len()].copy_from_slice(&value.data[..]);
461455
libosdp_sys::osdp_cmd_mfg {
462456
vendor_code: value.vendor_code.as_le(),
463457
command: value.command,

libosdp/src/events.rs

+11-17
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ impl From<u32> for OsdpCardFormats {
4545
}
4646
}
4747

48-
impl Into<u32> for OsdpCardFormats {
49-
fn into(self) -> u32 {
50-
match self {
48+
impl From<OsdpCardFormats> for u32 {
49+
fn from(val: OsdpCardFormats) -> Self {
50+
match val {
5151
OsdpCardFormats::Unspecified => {
5252
libosdp_sys::osdp_event_cardread_format_e_OSDP_CARD_FMT_RAW_UNSPECIFIED
5353
}
@@ -118,7 +118,7 @@ impl OsdpEventCardRead {
118118

119119
impl From<libosdp_sys::osdp_event_cardread> for OsdpEventCardRead {
120120
fn from(value: libosdp_sys::osdp_event_cardread) -> Self {
121-
let direction = if value.direction == 1 { true } else { false };
121+
let direction = value.direction == 1;
122122
let format = value.format.into();
123123
let len = value.length as usize;
124124
let (nr_bits, nr_bytes) = match format {
@@ -143,9 +143,7 @@ impl From<OsdpEventCardRead> for libosdp_sys::osdp_event_cardread {
143143
OsdpCardFormats::Weigand => value.nr_bits as i32,
144144
_ => value.data.len() as i32,
145145
};
146-
for i in 0..value.data.len() {
147-
data[i] = value.data[i];
148-
}
146+
data[..value.data.len()].copy_from_slice(&value.data[..]);
149147
libosdp_sys::osdp_event_cardread {
150148
reader_no: value.reader_no,
151149
format: value.format.clone().into(),
@@ -192,9 +190,7 @@ impl From<libosdp_sys::osdp_event_keypress> for OsdpEventKeyPress {
192190
impl From<OsdpEventKeyPress> for libosdp_sys::osdp_event_keypress {
193191
fn from(value: OsdpEventKeyPress) -> Self {
194192
let mut data = [0; libosdp_sys::OSDP_EVENT_KEYPRESS_MAX_DATALEN as usize];
195-
for i in 0..value.data.len() {
196-
data[i] = value.data[i];
197-
}
193+
data[..value.data.len()].copy_from_slice(&value.data[..]);
198194
libosdp_sys::osdp_event_keypress {
199195
reader_no: value.reader_no,
200196
length: value.data.len() as i32,
@@ -233,9 +229,7 @@ impl From<libosdp_sys::osdp_event_mfgrep> for OsdpEventMfgReply {
233229
impl From<OsdpEventMfgReply> for libosdp_sys::osdp_event_mfgrep {
234230
fn from(value: OsdpEventMfgReply) -> Self {
235231
let mut data = [0; libosdp_sys::OSDP_EVENT_MFGREP_MAX_DATALEN as usize];
236-
for i in 0..value.data.len() {
237-
data[i] = value.data[i];
238-
}
232+
data[..value.data.len()].copy_from_slice(&value.data[..]);
239233
libosdp_sys::osdp_event_mfgrep {
240234
vendor_code: value.vendor_code.as_le(),
241235
command: value.reply,
@@ -282,16 +276,16 @@ impl From<OsdpStatusReportType> for u32 {
282276
fn from(value: OsdpStatusReportType) -> Self {
283277
match value {
284278
OsdpStatusReportType::Input => {
285-
libosdp_sys::osdp_status_report_type_OSDP_STATUS_REPORT_INPUT as u32
279+
libosdp_sys::osdp_status_report_type_OSDP_STATUS_REPORT_INPUT
286280
}
287281
OsdpStatusReportType::Output => {
288-
libosdp_sys::osdp_status_report_type_OSDP_STATUS_REPORT_OUTPUT as u32
282+
libosdp_sys::osdp_status_report_type_OSDP_STATUS_REPORT_OUTPUT
289283
}
290284
OsdpStatusReportType::Remote => {
291-
libosdp_sys::osdp_status_report_type_OSDP_STATUS_REPORT_REMOTE as u32
285+
libosdp_sys::osdp_status_report_type_OSDP_STATUS_REPORT_REMOTE
292286
}
293287
OsdpStatusReportType::Local => {
294-
libosdp_sys::osdp_status_report_type_OSDP_STATUS_REPORT_LOCAL as u32
288+
libosdp_sys::osdp_status_report_type_OSDP_STATUS_REPORT_LOCAL
295289
}
296290
}
297291
}

libosdp/src/file.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ unsafe extern "C" fn raw_file_open(data: *mut c_void, file_id: i32, size: *mut i
3434
unsafe {
3535
*size = ctx.size as i32;
3636
}
37-
return 0;
37+
0
3838
}
3939

4040
unsafe extern "C" fn raw_file_read(
@@ -54,7 +54,7 @@ unsafe extern "C" fn raw_file_read(
5454
Err(_) => -1,
5555
};
5656
std::ptr::copy_nonoverlapping(read_buf.as_mut_ptr(), buf as *mut u8, len as usize);
57-
return len;
57+
len
5858
}
5959

6060
unsafe extern "C" fn raw_file_write(
@@ -82,7 +82,7 @@ unsafe extern "C" fn raw_file_close(data: *mut c_void) -> i32 {
8282
return -1;
8383
}
8484
let _ = ctx.file.take().unwrap();
85-
return 0;
85+
0
8686
}
8787

8888
impl OsdpFile {

libosdp/src/pd.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl PeripheralDevice {
9898
}
9999

100100
/// Set a vector of [`PdCapability`] for this PD.
101-
pub fn set_capabilities(&mut self, cap: &Vec<PdCapability>) {
101+
pub fn set_capabilities(&mut self, cap: &[PdCapability]) {
102102
let cap: Vec<libosdp_sys::osdp_pd_cap> = cap
103103
.iter()
104104
.map(|c| -> libosdp_sys::osdp_pd_cap { c.clone().into() })

libosdp/src/pdcap.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl FromStr for PdCapEntity {
6161
num_items,
6262
})
6363
} else {
64-
return Err(OsdpError::Parse(format!("PdCapEntry: {s}")));
64+
Err(OsdpError::Parse(format!("PdCapEntry: {s}")))
6565
}
6666
}
6767
}
@@ -249,9 +249,9 @@ impl From<libosdp_sys::osdp_pd_cap> for PdCapability {
249249
}
250250

251251
#[rustfmt::skip]
252-
impl Into<u8> for PdCapability {
253-
fn into(self) -> u8 {
254-
match self {
252+
impl From<PdCapability> for u8 {
253+
fn from(val: PdCapability) -> Self {
254+
match val {
255255
PdCapability::ContactStatusMonitoring(_) => {
256256
libosdp_sys::osdp_pd_cap_function_code_e_OSDP_PD_CAP_CONTACT_STATUS_MONITORING as u8
257257
}

libosdp/src/pdid.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ impl ConvertEndian for [u8; 4] {
5757
((self[0] as u32) << 24)
5858
| ((self[1] as u32) << 16)
5959
| ((self[2] as u32) << 8)
60-
| ((self[3] as u32) << 0)
60+
| (self[3] as u32)
6161
}
6262

6363
fn as_le(&self) -> u32 {
64-
((self[0] as u32) << 0)
64+
(self[0] as u32)
6565
| ((self[1] as u32) << 8)
6666
| ((self[2] as u32) << 16)
6767
| ((self[3] as u32) << 24)
@@ -74,7 +74,7 @@ impl ConvertEndian for (u8, u8, u8) {
7474
}
7575

7676
fn as_le(&self) -> u32 {
77-
((self.0 as u32) << 0) | ((self.1 as u32) << 8) | ((self.2 as u32) << 16)
77+
(self.0 as u32) | ((self.1 as u32) << 8) | ((self.2 as u32) << 16)
7878
}
7979
}
8080

libosdp/tests/common/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::{collections::hash_map::DefaultHasher, hash::{Hash, Hasher}};
88
pub mod device;
99
pub mod threadbus;
1010
pub mod memory_channel;
11-
pub mod unix_channel;
1211

1312
pub fn setup() {
1413
env_logger::builder()

libosdp/tests/common/unix_channel.rs

-82
This file was deleted.

osdpctl/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl CpConfig {
111111
name: config.get(&section, "name").unwrap(),
112112
channel: config.get(&section, "channel").unwrap(),
113113
address: config.getuint(&section, "address").unwrap().unwrap() as i32,
114-
key_store: KeyStore::create(runtime_dir.join("key.store"), &key)?,
114+
key_store: KeyStore::create(runtime_dir.join("key.store"), key)?,
115115
flags: OsdpFlag::empty(),
116116
});
117117
}

osdpctl/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ fn main() -> Result<()> {
130130
let config = sub_matches
131131
.get_one::<String>("CONFIG")
132132
.context("Device config file required")?;
133-
let config = PathBuf::from_str(&config)?;
133+
let config = PathBuf::from_str(config)?;
134134
let dev = DeviceConfig::new(&config, &rt_dir)?;
135135
let dest_path = cfg_dir.join(format!("{}.cfg", dev.name()));
136136
if dest_path.exists() {

0 commit comments

Comments
 (0)