diff --git a/Makefile b/Makefile index e54e706..2382eb8 100644 --- a/Makefile +++ b/Makefile @@ -59,6 +59,11 @@ dev: echo Installing jq... sudo apt install jq -y + # Details: https://github.com/Canop/bacon + # Usage: bacon + echo Installing bacon... + cargo install --locked bacon + deny-commit-on-master: ifeq ($(shell git symbolic-ref --short HEAD),master) $(error Direct commits to 'master' are not allowed.) diff --git a/rustfmt.toml b/rustfmt.toml index 7ebac41..043ddb2 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -8,3 +8,8 @@ hard_tabs = false use_small_heuristics = "Max" newline_style = "Unix" match_block_trailing_comma = true +wrap_comments = true +comment_width = 100 +normalize_comments = true +normalize_doc_attributes = true +reorder_impl_items = true diff --git a/src/lib.rs b/src/lib.rs index 2f17700..c160110 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,8 @@ mod macros; use core::mem::MaybeUninit; use core::{cmp, error, fmt, slice}; -/// Error for when the vector is full or the requested operation would need more space than the capacity. +/// Error for when the vector is full or the requested operation would need more space than the +/// capacity. /// /// See [`Vec::push()`] example for usage. #[derive(Debug)] @@ -131,7 +132,6 @@ impl Vec { /// Returns whether the vector is at maximum capacity. /// - /// /// # Example /// /// ```rust @@ -225,8 +225,8 @@ impl Vec { /// /// # Requirements /// - /// - `T` must implement [`Default`] because new elements are created with `T::default()` - /// when increasing the length. + /// - `T` must implement [`Default`] because new elements are created with `T::default()` when + /// increasing the length. /// /// # Errors /// @@ -310,7 +310,8 @@ impl Vec { self.get(0) } - /// Returns a mutable reference to the first element in the vector, or [`None`] if the vector is empty. + /// Returns a mutable reference to the first element in the vector, or [`None`] if the vector is + /// empty. /// /// # Example /// @@ -352,7 +353,8 @@ impl Vec { if self.is_empty() { None } else { self.get(self.len() - 1) } } - /// Returns a mutable reference to the last element in the vector, or [`None`] if the vector is empty. + /// Returns a mutable reference to the last element in the vector, or [`None`] if the vector is + /// empty. /// /// # Example /// @@ -405,7 +407,8 @@ impl Vec { } } - /// Returns a mutable reference to the element at the specified `index`, or [`None`] if out of bounds. + /// Returns a mutable reference to the element at the specified `index`, or [`None`] if out of + /// bounds. /// /// # Example /// @@ -475,8 +478,9 @@ impl Vec { } } - /// Returns (and removes) the last element from the vector if the predicate returns true, - /// or [`None`] if the vector is empty or the predicate returns false. + /// Returns (and removes) the last element from the vector if the predicate returns true, or + /// [`None`] if the vector is empty or the predicate returns false. + /// /// # Example /// /// Similar to [`Vec::pop()`], but needs a predicate @@ -591,7 +595,8 @@ impl Vec { /// /// # Errors /// - /// Returns [`CapacityError`] if adding elements of given slice would result in vector exceeding its capacity. + /// Returns [`CapacityError`] if adding elements of given slice would result in vector exceeding + /// its capacity. /// /// # Example /// @@ -645,7 +650,8 @@ impl Vec { /// /// # Errors /// - /// Returns [`CapacityError`] if adding elements from `other` would result in current vector exceeding its capacity. + /// Returns [`CapacityError`] if adding elements from `other` would result in current vector + /// exceeding its capacity. /// /// # Example /// @@ -688,8 +694,9 @@ impl Vec { self.length += 1; } - /// Drops all elements in given range. Needed when elements are considered to be going out of scope. - /// E.g.: when the vector is going out of scope, when methods such as [`Vec::clear()`] and [`Vec::set_len()`] are called. + /// Drops all elements in given range. Needed when elements are considered to be going out of + /// scope. E.g.: when the vector is going out of scope, when methods such as + /// [`Vec::clear()`] and [`Vec::set_len()`] are called. fn drop_range(&mut self, from: usize, to: usize) { for i in from..to { // SAFETY: @@ -770,8 +777,8 @@ impl<'a, T> Iterator for Iter<'a, T> { } impl<'a, T: 'a, const CAPACITY: usize> IntoIterator for &'a Vec { - type Item = &'a T; type IntoIter = Iter<'a, T>; + type Item = &'a T; fn into_iter(self) -> Self::IntoIter { self.iter() @@ -815,8 +822,8 @@ impl<'a, T> Iterator for IterMut<'a, T> { } impl<'a, T: 'a, const CAPACITY: usize> IntoIterator for &'a mut Vec { - type Item = &'a mut T; type IntoIter = IterMut<'a, T>; + type Item = &'a mut T; fn into_iter(self) -> Self::IntoIter { self.iter_mut() diff --git a/src/macros.rs b/src/macros.rs index 1185858..28bf121 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -8,11 +8,13 @@ /// - Example: `vec![u32; 8]` /// /// - `vec![value1, value2, ..., valueN]` -/// - Creates a static vector with the given values, inferring the type and capacity from the values. +/// - Creates a static vector with the given values, inferring the type and capacity from the +/// values. /// - Example: `vec![1, 2, 3]` /// /// - `vec![CAPACITY; value1, value2, ..., valueN]` -/// - Creates a static vector with the specified capacity and initializes it with the given values. +/// - Creates a static vector with the specified capacity and initializes it with the given +/// values. /// - Example: `vec![8; 1, 2, 3]` /// /// - `vec![Type; CAPACITY; Length]` @@ -21,7 +23,8 @@ /// /// # Panics /// -/// Panics if the specified capacity is zero, or the number of provided values exceeds the capacity, or the requested length is greater than the capacity. +/// Panics if the specified capacity is zero, or the number of provided values exceeds the capacity, +/// or the requested length is greater than the capacity. /// /// # Examples ///