From 62bd90ed252238dd06d20746d29749fe0a439469 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 12 Jun 2022 21:22:48 +0200 Subject: [PATCH] doc improvements --- src/core.rs | 9 +---- src/core/event_man.rs | 1 + src/core/events.rs | 1 + src/core/executable.rs | 1 + src/core/pool.rs | 77 ++++++++++++++++++++++++++++++------------ src/main.rs | 5 +-- 6 files changed, 61 insertions(+), 33 deletions(-) diff --git a/src/core.rs b/src/core.rs index 4e621eb..148ac45 100644 --- a/src/core.rs +++ b/src/core.rs @@ -1,11 +1,4 @@ -//! # Core components of the Flight Software Rust Crate (FSRC) collection. -//! -//! This includes components to perform the following tasks -//! -//! 1. Object Management with the [objects] module -//! 2. Task scheduling with the [executable] module -//! 3. Events with the [events] module and event management with the [event_man] module -//! 4. Pre-Allocated memory pools with the [pool] module +//! # Core components of the Flight Software Rust Crate (FSRC) collection pub mod event_man; pub mod events; pub mod executable; diff --git a/src/core/event_man.rs b/src/core/event_man.rs index 85d8d5b..865436b 100644 --- a/src/core/event_man.rs +++ b/src/core/event_man.rs @@ -1,3 +1,4 @@ +//! [Event][crate::core::events::Event] management and forwarding use crate::core::events::{Event, EventRaw, GroupId}; use std::collections::HashMap; diff --git a/src/core/events.rs b/src/core/events.rs index 221fbfd..58f6d68 100644 --- a/src/core/events.rs +++ b/src/core/events.rs @@ -1,3 +1,4 @@ +//! Event support module use num::pow; pub type GroupId = u16; diff --git a/src/core/executable.rs b/src/core/executable.rs index a1eb853..e44cd84 100644 --- a/src/core/executable.rs +++ b/src/core/executable.rs @@ -1,3 +1,4 @@ +//! Task scheduling module use bus::BusReader; use std::error::Error; use std::sync::mpsc::TryRecvError; diff --git a/src/core/pool.rs b/src/core/pool.rs index 1e5881d..adc81d7 100644 --- a/src/core/pool.rs +++ b/src/core/pool.rs @@ -1,4 +1,4 @@ -//! # Pool implementation providing sub-pools with fixed size memory blocks +//! # Pool implementation providing pre-allocated sub-pools with fixed size memory blocks //! //! This is a simple memory pool implementation which pre-allocates all sub-pools using a given pool //! configuration. After the pre-allocation, no dynamic memory allocation will be performed @@ -85,7 +85,6 @@ pub struct PoolCfg { cfg: Vec<(NumBlocks, usize)>, } - impl PoolCfg { pub fn new(cfg: Vec<(NumBlocks, usize)>) -> Self { PoolCfg { cfg } @@ -128,7 +127,7 @@ impl StoreAddr { #[derive(Debug, Clone, PartialEq)] pub enum StoreIdError { InvalidSubpool(u16), - InvalidPacketIdx(u16) + InvalidPacketIdx(u16), } #[derive(Debug, Clone, PartialEq)] @@ -226,10 +225,16 @@ impl LocalPool { fn addr_check(&self, addr: &StoreAddr) -> Result { let pool_idx = addr.pool_idx as usize; if pool_idx as usize >= self.pool_cfg.cfg.len() { - return Err(StoreError::InvalidStoreId(StoreIdError::InvalidSubpool(addr.pool_idx), Some(*addr))); + return Err(StoreError::InvalidStoreId( + StoreIdError::InvalidSubpool(addr.pool_idx), + Some(*addr), + )); } if addr.packet_idx >= self.pool_cfg.cfg[addr.pool_idx as usize].0 { - return Err(StoreError::InvalidStoreId(StoreIdError::InvalidPacketIdx(addr.packet_idx), Some(*addr))); + return Err(StoreError::InvalidStoreId( + StoreIdError::InvalidPacketIdx(addr.packet_idx), + Some(*addr), + )); } let size_list = self.sizes_lists.get(pool_idx).unwrap(); let curr_size = size_list[addr.packet_idx as usize]; @@ -287,7 +292,10 @@ impl LocalPool { } } } else { - return Err(StoreError::InvalidStoreId(StoreIdError::InvalidSubpool(subpool),None)); + return Err(StoreError::InvalidStoreId( + StoreIdError::InvalidSubpool(subpool), + None, + )); } Err(StoreError::StoreFull(subpool)) } @@ -327,12 +335,15 @@ mod tests { let pool_cfg = PoolCfg::new(vec![(4, 4), (2, 8), (1, 16)]); let mut local_pool = LocalPool::new(pool_cfg); // Try to access data which does not exist - let res = local_pool.read(&StoreAddr{ + let res = local_pool.read(&StoreAddr { packet_idx: 0, - pool_idx: 0 + pool_idx: 0, }); assert!(res.is_err()); - assert!(matches!(res.unwrap_err(), StoreError::DataDoesNotExist { .. })); + assert!(matches!( + res.unwrap_err(), + StoreError::DataDoesNotExist { .. } + )); let mut test_buf: [u8; 16] = [0; 16]; for (i, val) in test_buf.iter_mut().enumerate() { *val = i as u8; @@ -341,16 +352,19 @@ mod tests { assert!(res.is_ok()); let addr = res.unwrap(); // Only the second subpool has enough storage and only one bucket - assert_eq!(addr, StoreAddr { - pool_idx: 2, - packet_idx: 0 - }); + assert_eq!( + addr, + StoreAddr { + pool_idx: 2, + packet_idx: 0 + } + ); // The subpool is now full and the call should fail accordingly let res = local_pool.add(test_buf); assert!(res.is_err()); let err = res.unwrap_err(); - assert!(matches!(err, StoreError::StoreFull {..})); + assert!(matches!(err, StoreError::StoreFull { .. })); if let StoreError::StoreFull(subpool) = err { assert_eq!(subpool, 2); } @@ -361,7 +375,7 @@ mod tests { let buf_read_back = res.unwrap(); assert_eq!(buf_read_back.len(), 16); for (i, &val) in buf_read_back.iter().enumerate() { - assert_eq!(val , i as u8); + assert_eq!(val, i as u8); } // Delete the data @@ -373,7 +387,13 @@ mod tests { let res = local_pool.free_element(12); assert!(res.is_ok()); let (addr, buf_ref) = res.unwrap(); - assert_eq!(addr, StoreAddr {pool_idx: 2, packet_idx:0}); + assert_eq!( + addr, + StoreAddr { + pool_idx: 2, + packet_idx: 0 + } + ); assert_eq!(buf_ref.len(), 12); assert_eq!(buf_ref, [0; 12]); buf_ref[0] = 5; @@ -397,20 +417,32 @@ mod tests { } { - let addr = StoreAddr{pool_idx: 3, packet_idx: 0}; + let addr = StoreAddr { + pool_idx: 3, + packet_idx: 0, + }; let res = local_pool.read(&addr); assert!(res.is_err()); let err = res.unwrap_err(); - assert!(matches!(err, StoreError::InvalidStoreId(StoreIdError::InvalidSubpool(3), Some(_)))); + assert!(matches!( + err, + StoreError::InvalidStoreId(StoreIdError::InvalidSubpool(3), Some(_)) + )); } { - let addr = StoreAddr{pool_idx: 2, packet_idx: 1}; + let addr = StoreAddr { + pool_idx: 2, + packet_idx: 1, + }; assert_eq!(addr.raw(), 0x00020001); let res = local_pool.read(&addr); assert!(res.is_err()); let err = res.unwrap_err(); - assert!(matches!(err, StoreError::InvalidStoreId(StoreIdError::InvalidPacketIdx(1), Some(_)))); + assert!(matches!( + err, + StoreError::InvalidStoreId(StoreIdError::InvalidPacketIdx(1), Some(_)) + )); let data_too_large = [0; 20]; let res = local_pool.add(data_too_large); @@ -420,7 +452,10 @@ mod tests { let res = local_pool.free_element(LocalPool::MAX_SIZE + 1); assert!(res.is_err()); - assert_eq!(res.unwrap_err(), StoreError::DataTooLarge(LocalPool::MAX_SIZE + 1)); + assert_eq!( + res.unwrap_err(), + StoreError::DataTooLarge(LocalPool::MAX_SIZE + 1) + ); } { diff --git a/src/main.rs b/src/main.rs index 3033f62..f328e4d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1 @@ - -fn main() { - -} +fn main() {}