Archived
chore: configure clippy lints, improve unwrap usage
This commit is contained in:
1 parent
ec952b771c
commit
7b12b25053
6 files changed
+28
-25
No files matched your search
@@ -46,3 +46,6 @@ tempfile = "3"
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
rustdoc-args = ["--generate-link-to-definition"]
|
||||
|
||||
[lints.clippy]
|
||||
unwrap_used = "warn"
|
||||
@@ -0,0 +1 @@
|
||||
allow-unwrap-in-tests = true
|
||||
+2
-4
@@ -63,14 +63,13 @@ impl AckPdu {
|
||||
condition_code: ConditionCode,
|
||||
transaction_status: TransactionStatus,
|
||||
) -> Self {
|
||||
// Unwrap okay here, [new] can only fail on invalid directive codes.
|
||||
Self::new(
|
||||
pdu_header,
|
||||
FileDirectiveType::Eof,
|
||||
condition_code,
|
||||
transaction_status,
|
||||
)
|
||||
.unwrap()
|
||||
.expect("only fails when directive codes are invalid")
|
||||
}
|
||||
|
||||
/// Constructor for an ACK PDU acknowledging a Finished PDU.
|
||||
@@ -81,14 +80,13 @@ impl AckPdu {
|
||||
condition_code: ConditionCode,
|
||||
transaction_status: TransactionStatus,
|
||||
) -> Self {
|
||||
// Unwrap okay here, [new] can only fail on invalid directive codes.
|
||||
Self::new(
|
||||
pdu_header,
|
||||
FileDirectiveType::Finished,
|
||||
condition_code,
|
||||
transaction_status,
|
||||
)
|
||||
.unwrap()
|
||||
.expect("only fails when directive codes are invalid")
|
||||
}
|
||||
|
||||
/// PDU header.
|
||||
|
||||
+15
-11
@@ -148,7 +148,7 @@ pub mod zc {
|
||||
impl TryFrom<crate::ecss::tc::PusTcSecondaryHeader> for PusTcSecondaryHeader {
|
||||
type Error = PusError;
|
||||
fn try_from(value: crate::ecss::tc::PusTcSecondaryHeader) -> Result<Self, Self::Error> {
|
||||
if value.version != PusVersion::PusC {
|
||||
if !matches!(value.version, PusVersion::PusC) {
|
||||
return Err(PusError::VersionNotSupported(value.version.raw_value()));
|
||||
}
|
||||
Ok(PusTcSecondaryHeader {
|
||||
@@ -418,7 +418,8 @@ impl<'app_data> PusTcCreator<'app_data> {
|
||||
let mut digest = CRC_CCITT_FALSE.digest();
|
||||
let sph_zc = crate::zc::SpHeader::from(self.sp_header);
|
||||
digest.update(sph_zc.as_bytes());
|
||||
let pus_tc_header = zc::PusTcSecondaryHeader::try_from(self.sec_header).unwrap();
|
||||
let pus_tc_header = zc::PusTcSecondaryHeader::try_from(self.sec_header)
|
||||
.expect("the PUS version is hardcoded to PUS C");
|
||||
digest.update(pus_tc_header.as_bytes());
|
||||
digest.update(self.app_data);
|
||||
digest.finalize()
|
||||
@@ -429,7 +430,8 @@ impl<'app_data> PusTcCreator<'app_data> {
|
||||
let mut digest = CRC_CCITT_FALSE_NO_TABLE.digest();
|
||||
let sph_zc = crate::zc::SpHeader::from(self.sp_header);
|
||||
digest.update(sph_zc.as_bytes());
|
||||
let pus_tc_header = zc::PusTcSecondaryHeader::try_from(self.sec_header).unwrap();
|
||||
let pus_tc_header = zc::PusTcSecondaryHeader::try_from(self.sec_header)
|
||||
.expect("the PUS version is hardcoded to PUS C");
|
||||
digest.update(pus_tc_header.as_bytes());
|
||||
digest.update(self.app_data);
|
||||
digest.finalize()
|
||||
@@ -450,7 +452,8 @@ impl<'app_data> PusTcCreator<'app_data> {
|
||||
let start_idx = vec.len();
|
||||
vec.extend_from_slice(sph_zc.as_bytes());
|
||||
// The PUS version is hardcoded to PUS C
|
||||
let pus_tc_header = zc::PusTcSecondaryHeader::try_from(self.sec_header).unwrap();
|
||||
let pus_tc_header = zc::PusTcSecondaryHeader::try_from(self.sec_header)
|
||||
.expect("the PUS version is hardcoded to PUS C");
|
||||
vec.extend_from_slice(pus_tc_header.as_bytes());
|
||||
vec.extend_from_slice(self.app_data);
|
||||
if self.has_checksum() {
|
||||
@@ -664,11 +667,11 @@ impl<'buf> PusTcCreatorWithReservedAppData<'buf> {
|
||||
sp_header.write_to_be_bytes(&mut buf[0..CCSDS_HEADER_LEN])?;
|
||||
curr_idx += CCSDS_HEADER_LEN;
|
||||
let sec_header_len = size_of::<zc::PusTcSecondaryHeader>();
|
||||
let sec_header_zc = zc::PusTcSecondaryHeader::try_from(sec_header).unwrap();
|
||||
// Unwrap okay, this can not fail.
|
||||
let sec_header_zc = zc::PusTcSecondaryHeader::try_from(sec_header)
|
||||
.expect("the PUS version is hardcoded to PUS C");
|
||||
sec_header_zc
|
||||
.write_to(&mut buf[curr_idx..curr_idx + sec_header_len])
|
||||
.unwrap();
|
||||
.expect("buffer is large enough for secondary header");
|
||||
curr_idx += sec_header_len;
|
||||
let app_data_offset = curr_idx;
|
||||
curr_idx += app_data_len;
|
||||
@@ -916,8 +919,10 @@ impl<'raw_data> PusTcReader<'raw_data> {
|
||||
/// a CRC-16-CCITT checksum which is also verified.
|
||||
pub fn new(slice: &'raw_data [u8]) -> Result<Self, PusError> {
|
||||
let pus_tc = Self::new_no_checksum_verification(slice, true)?;
|
||||
// Unwrap for CRC16 okay, should always have some value.
|
||||
verify_crc16_ccitt_false_from_raw_to_pus_error(pus_tc.raw_data(), pus_tc.crc16().unwrap())?;
|
||||
verify_crc16_ccitt_false_from_raw_to_pus_error(
|
||||
pus_tc.raw_data(),
|
||||
pus_tc.crc16().expect("crc16 checksum shall not be `None`"),
|
||||
)?;
|
||||
Ok(pus_tc)
|
||||
}
|
||||
|
||||
@@ -925,10 +930,9 @@ impl<'raw_data> PusTcReader<'raw_data> {
|
||||
/// binary size and memory usage.
|
||||
pub fn new_checksum_no_table(slice: &'raw_data [u8]) -> Result<Self, PusError> {
|
||||
let pus_tc = Self::new_no_checksum_verification(slice, true)?;
|
||||
// Unwrap for CRC16 okay, should always have some value.
|
||||
verify_crc16_ccitt_false_from_raw_to_pus_error_no_table(
|
||||
pus_tc.raw_data(),
|
||||
pus_tc.crc16().unwrap(),
|
||||
pus_tc.crc16().expect("crc16 checksum shall not be `None`"),
|
||||
)?;
|
||||
Ok(pus_tc)
|
||||
}
|
||||
|
||||
@@ -192,11 +192,9 @@ impl<'stamp> PusTmSecondaryHeader<'stamp> {
|
||||
.into());
|
||||
}
|
||||
let pus_version = PusVersion::try_from(u4::new((buf[0] >> 4) & 0x0F));
|
||||
if let Err(version_raw) = pus_version {
|
||||
return Err(PusError::VersionNotSupported(version_raw));
|
||||
}
|
||||
let pus_version = pus_version.unwrap();
|
||||
if pus_version != PusVersion::PusA {
|
||||
let pus_version =
|
||||
pus_version.map_err(PusError::VersionNotSupported)?;
|
||||
if !matches!(pus_version, PusVersion::PusA) {
|
||||
return Err(PusError::VersionNotSupported(pus_version.raw_value()));
|
||||
}
|
||||
let mut msg_counter = None;
|
||||
@@ -466,9 +464,9 @@ impl<'time, 'src_data> PusTmCreator<'time, 'src_data> {
|
||||
if let Some(dest_id) = self.sec_header.dest_id {
|
||||
let mut dest_id_buf: [u8; core::mem::size_of::<u64>()] =
|
||||
[0; core::mem::size_of::<u64>()];
|
||||
// Unwrap okay, this can never fail because we created a buffer with the largest
|
||||
// possible size.
|
||||
let len = dest_id.write_to_be_bytes(&mut dest_id_buf).unwrap();
|
||||
let len = dest_id
|
||||
.write_to_be_bytes(&mut dest_id_buf)
|
||||
.expect("buffer is maximum possible size; this operation cannot fail");
|
||||
digest.update(&dest_id_buf[0..len]);
|
||||
}
|
||||
digest.update(self.sec_header.timestamp);
|
||||
|
||||
+1
-2
@@ -1250,9 +1250,8 @@ impl CcsdsPacketCreatorCommon {
|
||||
#[cfg(feature = "alloc")]
|
||||
pub fn to_vec(&self, len_written: usize, packet_data: &[u8]) -> alloc::vec::Vec<u8> {
|
||||
let mut vec = alloc::vec![0u8; len_written];
|
||||
// Can not fail, unless we messed up the len_written method..
|
||||
self.write_to_bytes(&mut vec, len_written, packet_data)
|
||||
.unwrap();
|
||||
.expect("buffer size shall match the len_written");
|
||||
vec
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user