Skip to content

Commit

Permalink
Fix issues reported by clippy
Browse files Browse the repository at this point in the history
Signed-off-by: Siddharth Chandrasekaran <[email protected]>
  • Loading branch information
sidcha committed Mar 13, 2024
1 parent 7209f14 commit f855272
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 122 deletions.
12 changes: 3 additions & 9 deletions libosdp/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,7 @@ impl From<libosdp_sys::osdp_cmd_text> for OsdpCommandText {
impl From<OsdpCommandText> for libosdp_sys::osdp_cmd_text {
fn from(value: OsdpCommandText) -> Self {
let mut data = [0; libosdp_sys::OSDP_CMD_TEXT_MAX_LEN as usize];
for i in 0..value.data.len() {
data[i] = value.data[i];
}
data[..value.data.len()].copy_from_slice(&value.data[..]);
libosdp_sys::osdp_cmd_text {
reader: value.reader,
control_code: value.control_code,
Expand Down Expand Up @@ -414,9 +412,7 @@ impl From<libosdp_sys::osdp_cmd_keyset> for OsdpCommandKeyset {
impl From<OsdpCommandKeyset> for libosdp_sys::osdp_cmd_keyset {
fn from(value: OsdpCommandKeyset) -> Self {
let mut data = [0; libosdp_sys::OSDP_CMD_KEYSET_KEY_MAX_LEN as usize];
for i in 0..value.data.len() {
data[i] = value.data[i];
}
data[..value.data.len()].copy_from_slice(&value.data[..]);
libosdp_sys::osdp_cmd_keyset {
type_: value.key_type,
length: value.data.len() as u8,
Expand Down Expand Up @@ -455,9 +451,7 @@ impl From<libosdp_sys::osdp_cmd_mfg> for OsdpCommandMfg {
impl From<OsdpCommandMfg> for libosdp_sys::osdp_cmd_mfg {
fn from(value: OsdpCommandMfg) -> Self {
let mut data = [0; libosdp_sys::OSDP_CMD_MFG_MAX_DATALEN as usize];
for i in 0..value.data.len() {
data[i] = value.data[i];
}
data[..value.data.len()].copy_from_slice(&value.data[..]);
libosdp_sys::osdp_cmd_mfg {
vendor_code: value.vendor_code.as_le(),
command: value.command,
Expand Down
28 changes: 11 additions & 17 deletions libosdp/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ impl From<u32> for OsdpCardFormats {
}
}

impl Into<u32> for OsdpCardFormats {
fn into(self) -> u32 {
match self {
impl From<OsdpCardFormats> for u32 {
fn from(val: OsdpCardFormats) -> Self {
match val {
OsdpCardFormats::Unspecified => {
libosdp_sys::osdp_event_cardread_format_e_OSDP_CARD_FMT_RAW_UNSPECIFIED
}
Expand Down Expand Up @@ -118,7 +118,7 @@ impl OsdpEventCardRead {

impl From<libosdp_sys::osdp_event_cardread> for OsdpEventCardRead {
fn from(value: libosdp_sys::osdp_event_cardread) -> Self {
let direction = if value.direction == 1 { true } else { false };
let direction = value.direction == 1;
let format = value.format.into();
let len = value.length as usize;
let (nr_bits, nr_bytes) = match format {
Expand All @@ -143,9 +143,7 @@ impl From<OsdpEventCardRead> for libosdp_sys::osdp_event_cardread {
OsdpCardFormats::Weigand => value.nr_bits as i32,
_ => value.data.len() as i32,
};
for i in 0..value.data.len() {
data[i] = value.data[i];
}
data[..value.data.len()].copy_from_slice(&value.data[..]);
libosdp_sys::osdp_event_cardread {
reader_no: value.reader_no,
format: value.format.clone().into(),
Expand Down Expand Up @@ -192,9 +190,7 @@ impl From<libosdp_sys::osdp_event_keypress> for OsdpEventKeyPress {
impl From<OsdpEventKeyPress> for libosdp_sys::osdp_event_keypress {
fn from(value: OsdpEventKeyPress) -> Self {
let mut data = [0; libosdp_sys::OSDP_EVENT_KEYPRESS_MAX_DATALEN as usize];
for i in 0..value.data.len() {
data[i] = value.data[i];
}
data[..value.data.len()].copy_from_slice(&value.data[..]);
libosdp_sys::osdp_event_keypress {
reader_no: value.reader_no,
length: value.data.len() as i32,
Expand Down Expand Up @@ -233,9 +229,7 @@ impl From<libosdp_sys::osdp_event_mfgrep> for OsdpEventMfgReply {
impl From<OsdpEventMfgReply> for libosdp_sys::osdp_event_mfgrep {
fn from(value: OsdpEventMfgReply) -> Self {
let mut data = [0; libosdp_sys::OSDP_EVENT_MFGREP_MAX_DATALEN as usize];
for i in 0..value.data.len() {
data[i] = value.data[i];
}
data[..value.data.len()].copy_from_slice(&value.data[..]);
libosdp_sys::osdp_event_mfgrep {
vendor_code: value.vendor_code.as_le(),
command: value.reply,
Expand Down Expand Up @@ -282,16 +276,16 @@ impl From<OsdpStatusReportType> for u32 {
fn from(value: OsdpStatusReportType) -> Self {
match value {
OsdpStatusReportType::Input => {
libosdp_sys::osdp_status_report_type_OSDP_STATUS_REPORT_INPUT as u32
libosdp_sys::osdp_status_report_type_OSDP_STATUS_REPORT_INPUT
}
OsdpStatusReportType::Output => {
libosdp_sys::osdp_status_report_type_OSDP_STATUS_REPORT_OUTPUT as u32
libosdp_sys::osdp_status_report_type_OSDP_STATUS_REPORT_OUTPUT
}
OsdpStatusReportType::Remote => {
libosdp_sys::osdp_status_report_type_OSDP_STATUS_REPORT_REMOTE as u32
libosdp_sys::osdp_status_report_type_OSDP_STATUS_REPORT_REMOTE
}
OsdpStatusReportType::Local => {
libosdp_sys::osdp_status_report_type_OSDP_STATUS_REPORT_LOCAL as u32
libosdp_sys::osdp_status_report_type_OSDP_STATUS_REPORT_LOCAL
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions libosdp/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ unsafe extern "C" fn raw_file_open(data: *mut c_void, file_id: i32, size: *mut i
unsafe {
*size = ctx.size as i32;
}
return 0;
0
}

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

unsafe extern "C" fn raw_file_write(
Expand Down Expand Up @@ -82,7 +82,7 @@ unsafe extern "C" fn raw_file_close(data: *mut c_void) -> i32 {
return -1;
}
let _ = ctx.file.take().unwrap();
return 0;
0
}

impl OsdpFile {
Expand Down
2 changes: 1 addition & 1 deletion libosdp/src/pd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl PeripheralDevice {
}

/// Set a vector of [`PdCapability`] for this PD.
pub fn set_capabilities(&mut self, cap: &Vec<PdCapability>) {
pub fn set_capabilities(&mut self, cap: &[PdCapability]) {
let cap: Vec<libosdp_sys::osdp_pd_cap> = cap
.iter()
.map(|c| -> libosdp_sys::osdp_pd_cap { c.clone().into() })
Expand Down
8 changes: 4 additions & 4 deletions libosdp/src/pdcap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl FromStr for PdCapEntity {
num_items,
})
} else {
return Err(OsdpError::Parse(format!("PdCapEntry: {s}")));
Err(OsdpError::Parse(format!("PdCapEntry: {s}")))
}
}
}
Expand Down Expand Up @@ -249,9 +249,9 @@ impl From<libosdp_sys::osdp_pd_cap> for PdCapability {
}

#[rustfmt::skip]
impl Into<u8> for PdCapability {
fn into(self) -> u8 {
match self {
impl From<PdCapability> for u8 {
fn from(val: PdCapability) -> Self {
match val {
PdCapability::ContactStatusMonitoring(_) => {
libosdp_sys::osdp_pd_cap_function_code_e_OSDP_PD_CAP_CONTACT_STATUS_MONITORING as u8
}
Expand Down
6 changes: 3 additions & 3 deletions libosdp/src/pdid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ impl ConvertEndian for [u8; 4] {
((self[0] as u32) << 24)
| ((self[1] as u32) << 16)
| ((self[2] as u32) << 8)
| ((self[3] as u32) << 0)
| (self[3] as u32)
}

fn as_le(&self) -> u32 {
((self[0] as u32) << 0)
(self[0] as u32)
| ((self[1] as u32) << 8)
| ((self[2] as u32) << 16)
| ((self[3] as u32) << 24)
Expand All @@ -74,7 +74,7 @@ impl ConvertEndian for (u8, u8, u8) {
}

fn as_le(&self) -> u32 {
((self.0 as u32) << 0) | ((self.1 as u32) << 8) | ((self.2 as u32) << 16)
(self.0 as u32) | ((self.1 as u32) << 8) | ((self.2 as u32) << 16)
}
}

Expand Down
1 change: 0 additions & 1 deletion libosdp/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::{collections::hash_map::DefaultHasher, hash::{Hash, Hasher}};
pub mod device;
pub mod threadbus;
pub mod memory_channel;
pub mod unix_channel;

pub fn setup() {
env_logger::builder()
Expand Down
82 changes: 0 additions & 82 deletions libosdp/tests/common/unix_channel.rs

This file was deleted.

2 changes: 1 addition & 1 deletion osdpctl/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl CpConfig {
name: config.get(&section, "name").unwrap(),
channel: config.get(&section, "channel").unwrap(),
address: config.getuint(&section, "address").unwrap().unwrap() as i32,
key_store: KeyStore::create(runtime_dir.join("key.store"), &key)?,
key_store: KeyStore::create(runtime_dir.join("key.store"), key)?,
flags: OsdpFlag::empty(),
});
}
Expand Down
2 changes: 1 addition & 1 deletion osdpctl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fn main() -> Result<()> {
let config = sub_matches
.get_one::<String>("CONFIG")
.context("Device config file required")?;
let config = PathBuf::from_str(&config)?;
let config = PathBuf::from_str(config)?;
let dev = DeviceConfig::new(&config, &rt_dir)?;
let dest_path = cfg_dir.join(format!("{}.cfg", dev.name()));
if dest_path.exists() {
Expand Down

0 comments on commit f855272

Please sign in to comment.