From 1f1aa68485e80830ddcc9f86fc3077fea1c0ffb6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 1 Dec 2023 14:34:16 +0100 Subject: [PATCH] remove std usages --- src/cfdp/pdu/nak.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/cfdp/pdu/nak.rs b/src/cfdp/pdu/nak.rs index 2b48ecb..5ec93d3 100644 --- a/src/cfdp/pdu/nak.rs +++ b/src/cfdp/pdu/nak.rs @@ -2,13 +2,15 @@ use crate::{ cfdp::{CrcFlag, Direction, LargeFileFlag}, ByteConversionError, }; -use core::marker::PhantomData; +use core::{marker::PhantomData, mem::size_of}; use super::{ add_pdu_crc, generic_length_checks_pdu_deserialization, CfdpPdu, FileDirectiveType, PduError, PduHeader, WritablePduPacket, }; +/// Helper type to encapsulate both normal file size segment requests and large file size segment +/// requests. #[derive(Debug, PartialEq, Eq, Clone)] pub enum SegmentRequests<'a> { U32Pairs(&'a [(u32, u32)]), @@ -246,7 +248,7 @@ impl WritablePduPacket for NakPduCreator<'_> { pub struct SegmentRequestIter<'a, T> { seq_req_raw: &'a [u8], current_idx: usize, - phantom: std::marker::PhantomData, + phantom: core::marker::PhantomData, } pub trait SegReqFromBytes { @@ -273,7 +275,7 @@ where fn next(&mut self) -> Option { let value = self.next_at_offset(self.current_idx); - self.current_idx += 2 * std::mem::size_of::(); + self.current_idx += 2 * size_of::(); value } } @@ -314,7 +316,7 @@ where if pairs.is_empty() && self.seq_req_raw.is_empty() { return true; } - let size = std::mem::size_of::(); + let size = size_of::(); if pairs.len() * 2 * size != self.seq_req_raw.len() { return false; } @@ -332,16 +334,16 @@ where impl SegmentRequestIter<'_, T> { fn next_at_offset(&self, mut offset: usize) -> Option<(T, T)> { - if offset + std::mem::size_of::() * 2 > self.seq_req_raw.len() { + if offset + size_of::() * 2 > self.seq_req_raw.len() { return None; } let start_offset = - T::from_bytes(&self.seq_req_raw[offset..offset + std::mem::size_of::()]); - offset += std::mem::size_of::(); + T::from_bytes(&self.seq_req_raw[offset..offset + size_of::()]); + offset += size_of::(); let end_offset = - T::from_bytes(&self.seq_req_raw[offset..offset + std::mem::size_of::()]); + T::from_bytes(&self.seq_req_raw[offset..offset + size_of::()]); Some((start_offset, end_offset)) } }