From 5a6a70f1b7b48234c04b1d002958cff9489ee179 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Mon, 13 Mar 2023 14:51:32 +0100 Subject: [PATCH] Force the compiler and clippy to return a warning when a function isn't documented --- src/kernel/system.rs | 1 + src/main.rs | 14 +++++++++++++- src/utility/list.rs | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/kernel/system.rs b/src/kernel/system.rs index bad8652..c813d96 100644 --- a/src/kernel/system.rs +++ b/src/kernel/system.rs @@ -30,6 +30,7 @@ impl<'a> System<'a> { } } + /// use thread_manager setter to send it system instance pub fn freeze(&'a mut self) { self.thread_manager.system.set(Option::Some(self)); } diff --git a/src/main.rs b/src/main.rs index 78b9e54..2e01f7d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,16 @@ + +#![warn(missing_docs)] +#![warn(clippy::missing_docs_in_private_items)] + +//! Crate burritos ((BurritOS Using Rust Really Improves The Operating System) +//! +//! Burritos is an educational operating system written in Rust +//! running on RISC-V emulator. + +/// Contain hardware simulated part of the machine mod simulator; mod kernel; +/// module containing useful tools which can be use in most part of the OS to ease the development of the OS pub mod utility; use kernel::system::System; @@ -7,5 +18,6 @@ use simulator::machine::Machine; fn main() { let machine = Machine::init_machine(); - let _system = System::new(machine); + let mut system = System::new(machine); + system.freeze(); } diff --git a/src/utility/list.rs b/src/utility/list.rs index f6efb50..b3cc66f 100644 --- a/src/utility/list.rs +++ b/src/utility/list.rs @@ -1,9 +1,13 @@ +/// Data structure and definition of a genericsingle-linked LIFO list. +/// +/// This is a #[derive(PartialEq)] pub struct List { head: Link, } + type Link = Option>>; #[derive(PartialEq)] @@ -13,6 +17,8 @@ struct Node { } impl List { + + /// Create an empty list pub fn new() -> Self { List { head: None } } @@ -94,18 +100,26 @@ impl List { found } + /// Return true if the list is empty, false otherwise pub fn is_empty(&self) -> bool { self.head.is_none() } + /// Turn the list into an iterator for use in a for loop per example. + /// + /// When you iter using into_iter, elements are remove from the list pub fn into_iter(self) -> IntoIter { IntoIter(self) } + /// Turn the list into an iterator for use in a for loop + /// + /// When you iter using this method, elements are dereferenced pub fn iter(&self) -> Iter<'_, T> { Iter { next: self.head.as_deref() } } + /// Same as iter but make the iterator mutable pub fn iter_mut(&mut self) -> IterMut<'_, T> { IterMut { next: self.head.as_deref_mut() } } @@ -120,6 +134,7 @@ impl Drop for List { } } +/// Iterator structure for use in a for loop, pop elements before returning it pub struct IntoIter(List); impl Iterator for IntoIter { @@ -130,6 +145,7 @@ impl Iterator for IntoIter { } } +/// Iterator structure for use in a for loop, dereference before returning it pub struct Iter<'a, T> { next: Option<&'a Node>, } @@ -144,6 +160,7 @@ impl<'a, T> Iterator for Iter<'a, T> { } } +/// Same as Iter structure, returned item are mutable pub struct IterMut<'a, T> { next: Option<&'a mut Node>, }