Skip to content

Format #44

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 2 commits into from
May 28, 2025
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
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand Down
5 changes: 5 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
37 changes: 22 additions & 15 deletions src/lib.rs

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In src/lib.rs, the pop_if function implementation could potentially panic when called on an empty vector. Consider adding a bounds check similar to what's in the pop function to prevent undefined behavior when the vector is empty.

Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -131,7 +132,6 @@ impl<T, const CAPACITY: usize> Vec<T, CAPACITY> {

/// Returns whether the vector is at maximum capacity.
///
///
/// # Example
///
/// ```rust
Expand Down Expand Up @@ -225,8 +225,8 @@ impl<T, const CAPACITY: usize> Vec<T, CAPACITY> {
///
/// # 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
///
Expand Down Expand Up @@ -310,7 +310,8 @@ impl<T, const CAPACITY: usize> Vec<T, CAPACITY> {
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
///
Expand Down Expand Up @@ -352,7 +353,8 @@ impl<T, const CAPACITY: usize> Vec<T, CAPACITY> {
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
///
Expand Down Expand Up @@ -405,7 +407,8 @@ impl<T, const CAPACITY: usize> Vec<T, CAPACITY> {
}
}

/// 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
///
Expand Down Expand Up @@ -475,8 +478,9 @@ impl<T, const CAPACITY: usize> Vec<T, CAPACITY> {
}
}

/// 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
Expand Down Expand Up @@ -591,7 +595,8 @@ impl<T, const CAPACITY: usize> Vec<T, CAPACITY> {
///
/// # 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
///
Expand Down Expand Up @@ -645,7 +650,8 @@ impl<T, const CAPACITY: usize> Vec<T, CAPACITY> {
///
/// # 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
///
Expand Down Expand Up @@ -688,8 +694,9 @@ impl<T, const CAPACITY: usize> Vec<T, CAPACITY> {
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:
Expand Down Expand Up @@ -770,8 +777,8 @@ impl<'a, T> Iterator for Iter<'a, T> {
}

impl<'a, T: 'a, const CAPACITY: usize> IntoIterator for &'a Vec<T, CAPACITY> {
type Item = &'a T;
type IntoIter = Iter<'a, T>;
type Item = &'a T;

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

impl<'a, T: 'a, const CAPACITY: usize> IntoIterator for &'a mut Vec<T, CAPACITY> {
type Item = &'a mut T;
type IntoIter = IterMut<'a, T>;
type Item = &'a mut T;

fn into_iter(self) -> Self::IntoIter {
self.iter_mut()
Expand Down
9 changes: 6 additions & 3 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]`
Expand All @@ -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
///
Expand Down