Skip to content

rustfmt: run on doc comments #414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
format_code_in_doc_comments = true
1 change: 0 additions & 1 deletion src/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
1 change: 0 additions & 1 deletion src/defmt.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! Defmt implementations for heapless types
//!

use crate::Vec;
use defmt::Formatter;
Expand Down
1 change: 0 additions & 1 deletion src/deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down
5 changes: 3 additions & 2 deletions src/histbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 {
Expand Down
50 changes: 35 additions & 15 deletions src/indexmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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),
/// }
/// }
///
Expand Down Expand Up @@ -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.
Expand All @@ -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),
/// }
/// }
///
Expand Down Expand Up @@ -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();
Expand Down
12 changes: 8 additions & 4 deletions src/indexset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]`"
Expand Down
20 changes: 10 additions & 10 deletions src/sorted_linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
11 changes: 7 additions & 4 deletions src/spsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> = {
Expand All @@ -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
//! }
Expand Down
15 changes: 8 additions & 7 deletions src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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]);
/// ```
Expand Down