rustfmt: run on doc comments

This commit is contained in:
Alex Martens 2023-11-17 08:24:17 -08:00
parent d9b06bd487
commit 5ee530c479
12 changed files with 73 additions and 47 deletions

View File

@ -94,7 +94,7 @@ jobs:
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt

1
rustfmt.toml Normal file
View File

@ -0,0 +1 @@
format_code_in_doc_comments = true

View File

@ -203,7 +203,6 @@ where
/// // Print 1, 2, 3, 4 in arbitrary order
/// for x in heap.iter() {
/// println!("{}", x);
///
/// }
/// ```
pub fn iter(&self) -> slice::Iter<'_, T> {

View File

@ -1,5 +1,4 @@
//! Defmt implementations for heapless types
//!
use crate::Vec;
use defmt::Formatter;

View File

@ -385,7 +385,6 @@ impl<T: fmt::Debug, const N: usize> fmt::Debug for Deque<T, N> {
/// An iterator that moves out of a [`Deque`].
///
/// This struct is created by calling the `into_iter` method.
///
#[derive(Clone)]
pub struct IntoIter<T, const N: usize> {
deque: Deque<T, N>,

View File

@ -28,7 +28,9 @@ use core::slice;
/// assert_eq!(buf.recent(), Some(&4));
///
/// // To access all elements in an unspecified order, use `as_slice()`.
/// for el in buf.as_slice() { println!("{:?}", el); }
/// for el in buf.as_slice() {
/// println!("{:?}", el);
/// }
///
/// // Now we can prepare an average of all values, which comes out to 4.
/// let avg = buf.as_slice().iter().sum::<usize>() / buf.len();
@ -232,7 +234,6 @@ impl<T, const N: usize> HistoryBuffer<T, N> {
/// for (x, y) in buffer.oldest_ordered().zip(expected.iter()) {
/// assert_eq!(x, y)
/// }
///
/// ```
pub fn oldest_ordered(&self) -> OldestOrdered<'_, T, N> {
if self.filled {

View File

@ -25,15 +25,25 @@ use crate::Vec;
/// let mut book_reviews = FnvIndexMap::<_, _, 16>::new();
///
/// // review some books.
/// book_reviews.insert("Adventures of Huckleberry Finn", "My favorite book.").unwrap();
/// book_reviews.insert("Grimms' Fairy Tales", "Masterpiece.").unwrap();
/// book_reviews.insert("Pride and Prejudice", "Very enjoyable.").unwrap();
/// book_reviews.insert("The Adventures of Sherlock Holmes", "Eye lyked it alot.").unwrap();
/// book_reviews
/// .insert("Adventures of Huckleberry Finn", "My favorite book.")
/// .unwrap();
/// book_reviews
/// .insert("Grimms' Fairy Tales", "Masterpiece.")
/// .unwrap();
/// book_reviews
/// .insert("Pride and Prejudice", "Very enjoyable.")
/// .unwrap();
/// book_reviews
/// .insert("The Adventures of Sherlock Holmes", "Eye lyked it alot.")
/// .unwrap();
///
/// // check for a specific one.
/// if !book_reviews.contains_key("Les Misérables") {
/// println!("We've got {} reviews, but Les Misérables ain't one.",
/// book_reviews.len());
/// println!(
/// "We've got {} reviews, but Les Misérables ain't one.",
/// book_reviews.len()
/// );
/// }
///
/// // oops, this review has a lot of spelling mistakes, let's delete it.
@ -44,7 +54,7 @@ use crate::Vec;
/// for book in &to_find {
/// match book_reviews.get(book) {
/// Some(review) => println!("{}: {}", book, review),
/// None => println!("{} is unreviewed.", book)
/// None => println!("{} is unreviewed.", book),
/// }
/// }
///
@ -498,15 +508,25 @@ where
/// let mut book_reviews = FnvIndexMap::<_, _, 16>::new();
///
/// // review some books.
/// book_reviews.insert("Adventures of Huckleberry Finn", "My favorite book.").unwrap();
/// book_reviews.insert("Grimms' Fairy Tales", "Masterpiece.").unwrap();
/// book_reviews.insert("Pride and Prejudice", "Very enjoyable.").unwrap();
/// book_reviews.insert("The Adventures of Sherlock Holmes", "Eye lyked it alot.").unwrap();
/// book_reviews
/// .insert("Adventures of Huckleberry Finn", "My favorite book.")
/// .unwrap();
/// book_reviews
/// .insert("Grimms' Fairy Tales", "Masterpiece.")
/// .unwrap();
/// book_reviews
/// .insert("Pride and Prejudice", "Very enjoyable.")
/// .unwrap();
/// book_reviews
/// .insert("The Adventures of Sherlock Holmes", "Eye lyked it alot.")
/// .unwrap();
///
/// // check for a specific one.
/// if !book_reviews.contains_key("Les Misérables") {
/// println!("We've got {} reviews, but Les Misérables ain't one.",
/// book_reviews.len());
/// println!(
/// "We've got {} reviews, but Les Misérables ain't one.",
/// book_reviews.len()
/// );
/// }
///
/// // oops, this review has a lot of spelling mistakes, let's delete it.
@ -517,7 +537,7 @@ where
/// for book in &to_find {
/// match book_reviews.get(book) {
/// Some(review) => println!("{}: {}", book, review),
/// None => println!("{} is unreviewed.", book)
/// None => println!("{} is unreviewed.", book),
/// }
/// }
///
@ -759,8 +779,8 @@ where
/* Public API */
/// Returns an entry for the corresponding key
/// ```
/// use heapless::FnvIndexMap;
/// use heapless::Entry;
/// use heapless::FnvIndexMap;
/// let mut map = FnvIndexMap::<_, _, 16>::new();
/// if let Entry::Vacant(v) = map.entry("a") {
/// v.insert(1).unwrap();

View File

@ -27,8 +27,10 @@ use hash32::{BuildHasherDefault, FnvHasher};
///
/// // Check for a specific one.
/// if !books.contains("The Winds of Winter") {
/// println!("We have {} books, but The Winds of Winter ain't one.",
/// books.len());
/// println!(
/// "We have {} books, but The Winds of Winter ain't one.",
/// books.len()
/// );
/// }
///
/// // Remove a book.
@ -67,8 +69,10 @@ pub type FnvIndexSet<T, const N: usize> = IndexSet<T, BuildHasherDefault<FnvHash
///
/// // Check for a specific one.
/// if !books.contains("The Winds of Winter") {
/// println!("We have {} books, but The Winds of Winter ain't one.",
/// books.len());
/// println!(
/// "We have {} books, but The Winds of Winter ain't one.",
/// books.len()
/// );
/// }
///
/// // Remove a book.

View File

@ -42,7 +42,6 @@
//! structure.
//!
//! List of currently implemented data structures:
//!
#![cfg_attr(
any(arm_llsc, target_arch = "x86"),
doc = "- [`Arc`](pool::arc::Arc) -- like `std::sync::Arc` but backed by a lock-free memory pool rather than `#[global_allocator]`"

View File

@ -6,7 +6,7 @@
//! # Examples
//!
//! ```
//! use heapless::sorted_linked_list::{SortedLinkedList, Max};
//! use heapless::sorted_linked_list::{Max, SortedLinkedList};
//! let mut ll: SortedLinkedList<_, _, Max, 3> = SortedLinkedList::new_usize();
//!
//! // The largest value will always be first
@ -292,7 +292,7 @@ where
/// # Example
///
/// ```
/// use heapless::sorted_linked_list::{SortedLinkedList, Max};
/// use heapless::sorted_linked_list::{Max, SortedLinkedList};
/// let mut ll: SortedLinkedList<_, _, Max, 3> = SortedLinkedList::new_usize();
///
/// // The largest value will always be first
@ -322,7 +322,7 @@ where
/// # Example
///
/// ```
/// use heapless::sorted_linked_list::{SortedLinkedList, Max};
/// use heapless::sorted_linked_list::{Max, SortedLinkedList};
/// let mut ll: SortedLinkedList<_, _, Max, 3> = SortedLinkedList::new_usize();
///
/// ll.push(1).unwrap();
@ -346,7 +346,7 @@ where
/// # Example
///
/// ```
/// use heapless::sorted_linked_list::{SortedLinkedList, Max};
/// use heapless::sorted_linked_list::{Max, SortedLinkedList};
/// let mut ll: SortedLinkedList<_, _, Max, 3> = SortedLinkedList::new_usize();
///
/// ll.push(1).unwrap();
@ -404,7 +404,7 @@ where
/// # Example
///
/// ```
/// use heapless::sorted_linked_list::{SortedLinkedList, Max, Min};
/// use heapless::sorted_linked_list::{Max, Min, SortedLinkedList};
/// let mut ll_max: SortedLinkedList<_, _, Max, 3> = SortedLinkedList::new_usize();
///
/// // The largest value will always be first
@ -453,7 +453,7 @@ where
/// # Example
///
/// ```
/// use heapless::sorted_linked_list::{SortedLinkedList, Max};
/// use heapless::sorted_linked_list::{Max, SortedLinkedList};
/// let mut ll: SortedLinkedList<_, _, Max, 3> = SortedLinkedList::new_usize();
///
/// ll.push(1).unwrap();
@ -477,7 +477,7 @@ where
/// # Example
///
/// ```
/// use heapless::sorted_linked_list::{SortedLinkedList, Max};
/// use heapless::sorted_linked_list::{Max, SortedLinkedList};
/// let mut ll: SortedLinkedList<_, _, Max, 3> = SortedLinkedList::new_usize();
///
/// assert_eq!(ll.is_full(), false);
@ -499,7 +499,7 @@ where
/// # Example
///
/// ```
/// use heapless::sorted_linked_list::{SortedLinkedList, Max};
/// use heapless::sorted_linked_list::{Max, SortedLinkedList};
/// let mut ll: SortedLinkedList<_, _, Max, 3> = SortedLinkedList::new_usize();
///
/// assert_eq!(ll.is_empty(), true);
@ -589,7 +589,7 @@ where
/// # Example
///
/// ```
/// use heapless::sorted_linked_list::{SortedLinkedList, Max};
/// use heapless::sorted_linked_list::{Max, SortedLinkedList};
/// let mut ll: SortedLinkedList<_, _, Max, 3> = SortedLinkedList::new_usize();
///
/// ll.push(1).unwrap();
@ -619,7 +619,7 @@ where
/// # Example
///
/// ```
/// use heapless::sorted_linked_list::{SortedLinkedList, Max};
/// use heapless::sorted_linked_list::{Max, SortedLinkedList};
/// let mut ll: SortedLinkedList<_, _, Max, 3> = SortedLinkedList::new_usize();
///
/// ll.push(1).unwrap();

View File

@ -37,7 +37,10 @@
//! ```
//! use heapless::spsc::{Producer, Queue};
//!
//! enum Event { A, B }
//! enum Event {
//! A,
//! B,
//! }
//!
//! fn main() {
//! let queue: &'static mut Queue<Event, 4> = {
@ -52,9 +55,9 @@
//!
//! loop {
//! match consumer.dequeue() {
//! Some(Event::A) => { /* .. */ },
//! Some(Event::B) => { /* .. */ },
//! None => { /* sleep */ },
//! Some(Event::A) => { /* .. */ }
//! Some(Event::B) => { /* .. */ }
//! None => { /* sleep */ }
//! }
//! # break
//! }

View File

@ -7,7 +7,6 @@ use core::{cmp::Ordering, fmt, hash, iter::FromIterator, mem::MaybeUninit, ops,
/// ```
/// use heapless::Vec;
///
///
/// // A vector with a fixed capacity of 8 elements allocated on the stack
/// let mut vec = Vec::<_, 8>::new();
/// vec.push(1);
@ -419,7 +418,7 @@ impl<T, const N: usize> Vec<T, N> {
/// Vec::from_iter([0, 0, 1].iter().cloned()),
/// ]
/// .iter()
/// .cloned()
/// .cloned(),
/// );
/// // SAFETY:
/// // 1. `old_len..0` is empty so no elements need to be initialized.
@ -712,11 +711,13 @@ impl<T, const N: usize> Vec<T, N> {
/// use heapless::Vec;
///
/// let mut vec: Vec<_, 8> = Vec::from_slice(&[1, 2, 3, 4]).unwrap();
/// vec.retain_mut(|x| if *x <= 3 {
/// *x += 1;
/// true
/// } else {
/// false
/// vec.retain_mut(|x| {
/// if *x <= 3 {
/// *x += 1;
/// true
/// } else {
/// false
/// }
/// });
/// assert_eq!(vec, [2, 3, 4]);
/// ```