Skip to content

Commit b145b84

Browse files
Format (#44)
* Add format rules * Install bacon
1 parent 889a65d commit b145b84

File tree

4 files changed

+38
-18
lines changed

4 files changed

+38
-18
lines changed

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ dev:
5959
echo Installing jq...
6060
sudo apt install jq -y
6161

62+
# Details: https://github.com/Canop/bacon
63+
# Usage: bacon
64+
echo Installing bacon...
65+
cargo install --locked bacon
66+
6267
deny-commit-on-master:
6368
ifeq ($(shell git symbolic-ref --short HEAD),master)
6469
$(error Direct commits to 'master' are not allowed.)

rustfmt.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ hard_tabs = false
88
use_small_heuristics = "Max"
99
newline_style = "Unix"
1010
match_block_trailing_comma = true
11+
wrap_comments = true
12+
comment_width = 100
13+
normalize_comments = true
14+
normalize_doc_attributes = true
15+
reorder_impl_items = true

src/lib.rs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ mod macros;
88
use core::mem::MaybeUninit;
99
use core::{cmp, error, fmt, slice};
1010

11-
/// Error for when the vector is full or the requested operation would need more space than the capacity.
11+
/// Error for when the vector is full or the requested operation would need more space than the
12+
/// capacity.
1213
///
1314
/// See [`Vec::push()`] example for usage.
1415
#[derive(Debug)]
@@ -131,7 +132,6 @@ impl<T, const CAPACITY: usize> Vec<T, CAPACITY> {
131132

132133
/// Returns whether the vector is at maximum capacity.
133134
///
134-
///
135135
/// # Example
136136
///
137137
/// ```rust
@@ -225,8 +225,8 @@ impl<T, const CAPACITY: usize> Vec<T, CAPACITY> {
225225
///
226226
/// # Requirements
227227
///
228-
/// - `T` must implement [`Default`] because new elements are created with `T::default()`
229-
/// when increasing the length.
228+
/// - `T` must implement [`Default`] because new elements are created with `T::default()` when
229+
/// increasing the length.
230230
///
231231
/// # Errors
232232
///
@@ -310,7 +310,8 @@ impl<T, const CAPACITY: usize> Vec<T, CAPACITY> {
310310
self.get(0)
311311
}
312312

313-
/// Returns a mutable reference to the first element in the vector, or [`None`] if the vector is empty.
313+
/// Returns a mutable reference to the first element in the vector, or [`None`] if the vector is
314+
/// empty.
314315
///
315316
/// # Example
316317
///
@@ -352,7 +353,8 @@ impl<T, const CAPACITY: usize> Vec<T, CAPACITY> {
352353
if self.is_empty() { None } else { self.get(self.len() - 1) }
353354
}
354355

355-
/// Returns a mutable reference to the last element in the vector, or [`None`] if the vector is empty.
356+
/// Returns a mutable reference to the last element in the vector, or [`None`] if the vector is
357+
/// empty.
356358
///
357359
/// # Example
358360
///
@@ -405,7 +407,8 @@ impl<T, const CAPACITY: usize> Vec<T, CAPACITY> {
405407
}
406408
}
407409

408-
/// Returns a mutable reference to the element at the specified `index`, or [`None`] if out of bounds.
410+
/// Returns a mutable reference to the element at the specified `index`, or [`None`] if out of
411+
/// bounds.
409412
///
410413
/// # Example
411414
///
@@ -475,8 +478,9 @@ impl<T, const CAPACITY: usize> Vec<T, CAPACITY> {
475478
}
476479
}
477480

478-
/// Returns (and removes) the last element from the vector if the predicate returns true,
479-
/// or [`None`] if the vector is empty or the predicate returns false.
481+
/// Returns (and removes) the last element from the vector if the predicate returns true, or
482+
/// [`None`] if the vector is empty or the predicate returns false.
483+
///
480484
/// # Example
481485
///
482486
/// Similar to [`Vec::pop()`], but needs a predicate
@@ -591,7 +595,8 @@ impl<T, const CAPACITY: usize> Vec<T, CAPACITY> {
591595
///
592596
/// # Errors
593597
///
594-
/// Returns [`CapacityError`] if adding elements of given slice would result in vector exceeding its capacity.
598+
/// Returns [`CapacityError`] if adding elements of given slice would result in vector exceeding
599+
/// its capacity.
595600
///
596601
/// # Example
597602
///
@@ -645,7 +650,8 @@ impl<T, const CAPACITY: usize> Vec<T, CAPACITY> {
645650
///
646651
/// # Errors
647652
///
648-
/// Returns [`CapacityError`] if adding elements from `other` would result in current vector exceeding its capacity.
653+
/// Returns [`CapacityError`] if adding elements from `other` would result in current vector
654+
/// exceeding its capacity.
649655
///
650656
/// # Example
651657
///
@@ -688,8 +694,9 @@ impl<T, const CAPACITY: usize> Vec<T, CAPACITY> {
688694
self.length += 1;
689695
}
690696

691-
/// Drops all elements in given range. Needed when elements are considered to be going out of scope.
692-
/// E.g.: when the vector is going out of scope, when methods such as [`Vec::clear()`] and [`Vec::set_len()`] are called.
697+
/// Drops all elements in given range. Needed when elements are considered to be going out of
698+
/// scope. E.g.: when the vector is going out of scope, when methods such as
699+
/// [`Vec::clear()`] and [`Vec::set_len()`] are called.
693700
fn drop_range(&mut self, from: usize, to: usize) {
694701
for i in from..to {
695702
// SAFETY:
@@ -770,8 +777,8 @@ impl<'a, T> Iterator for Iter<'a, T> {
770777
}
771778

772779
impl<'a, T: 'a, const CAPACITY: usize> IntoIterator for &'a Vec<T, CAPACITY> {
773-
type Item = &'a T;
774780
type IntoIter = Iter<'a, T>;
781+
type Item = &'a T;
775782

776783
fn into_iter(self) -> Self::IntoIter {
777784
self.iter()
@@ -815,8 +822,8 @@ impl<'a, T> Iterator for IterMut<'a, T> {
815822
}
816823

817824
impl<'a, T: 'a, const CAPACITY: usize> IntoIterator for &'a mut Vec<T, CAPACITY> {
818-
type Item = &'a mut T;
819825
type IntoIter = IterMut<'a, T>;
826+
type Item = &'a mut T;
820827

821828
fn into_iter(self) -> Self::IntoIter {
822829
self.iter_mut()

src/macros.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
/// - Example: `vec![u32; 8]`
99
///
1010
/// - `vec![value1, value2, ..., valueN]`
11-
/// - Creates a static vector with the given values, inferring the type and capacity from the values.
11+
/// - Creates a static vector with the given values, inferring the type and capacity from the
12+
/// values.
1213
/// - Example: `vec![1, 2, 3]`
1314
///
1415
/// - `vec![CAPACITY; value1, value2, ..., valueN]`
15-
/// - Creates a static vector with the specified capacity and initializes it with the given values.
16+
/// - Creates a static vector with the specified capacity and initializes it with the given
17+
/// values.
1618
/// - Example: `vec![8; 1, 2, 3]`
1719
///
1820
/// - `vec![Type; CAPACITY; Length]`
@@ -21,7 +23,8 @@
2123
///
2224
/// # Panics
2325
///
24-
/// 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.
26+
/// Panics if the specified capacity is zero, or the number of provided values exceeds the capacity,
27+
/// or the requested length is greater than the capacity.
2528
///
2629
/// # Examples
2730
///

0 commit comments

Comments
 (0)