Force the compiler and clippy to return a warning when a function isn't documented
This commit is contained in:
@ -1,9 +1,13 @@
|
||||
|
||||
/// Data structure and definition of a genericsingle-linked LIFO list.
|
||||
///
|
||||
/// This is a
|
||||
#[derive(PartialEq)]
|
||||
pub struct List<T: PartialEq> {
|
||||
head: Link<T>,
|
||||
}
|
||||
|
||||
|
||||
type Link<T> = Option<Box<Node<T>>>;
|
||||
|
||||
#[derive(PartialEq)]
|
||||
@ -13,6 +17,8 @@ struct Node<T> {
|
||||
}
|
||||
|
||||
impl<T: PartialEq> List<T> {
|
||||
|
||||
/// Create an empty list
|
||||
pub fn new() -> Self {
|
||||
List { head: None }
|
||||
}
|
||||
@ -94,18 +100,26 @@ impl<T: PartialEq> List<T> {
|
||||
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<T> {
|
||||
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<T: PartialEq> Drop for List<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Iterator structure for use in a for loop, pop elements before returning it
|
||||
pub struct IntoIter<T: PartialEq>(List<T>);
|
||||
|
||||
impl<T: PartialEq> Iterator for IntoIter<T> {
|
||||
@ -130,6 +145,7 @@ impl<T: PartialEq> Iterator for IntoIter<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Iterator structure for use in a for loop, dereference before returning it
|
||||
pub struct Iter<'a, T> {
|
||||
next: Option<&'a Node<T>>,
|
||||
}
|
||||
@ -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<T>>,
|
||||
}
|
||||
|
Reference in New Issue
Block a user