Skip to content
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
3 changes: 2 additions & 1 deletion src/from_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ where
/// Create array where each array element `T` is returned by the `f` call.
#[inline]
pub fn from_fn(mut f: impl FnMut(usize) -> T) -> Self {
Self::try_from_fn::<Infallible>(|n| Ok(f(n))).expect("should never fail")
let Ok(ret) = Self::try_from_fn::<Infallible>(|n| Ok(f(n)));
ret
}

/// Create array fallibly where each array element `T` is returned by the `f` call, or return
Expand Down
22 changes: 16 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@
clippy::checked_conversions,
clippy::from_iter_instead_of_collect,
clippy::missing_errors_doc,
clippy::missing_panics_doc,
clippy::mod_module_files,
clippy::must_use_candidate,
clippy::implicit_saturating_sub,
clippy::panic,
clippy::panic_in_result_fn,
clippy::ptr_as_ptr,
clippy::ref_as_ptr,
clippy::semicolon_if_nothing_returned,
clippy::unwrap_used,
missing_docs,
missing_debug_implementations,
Expand Down Expand Up @@ -209,15 +214,13 @@ where
}

/// Returns a pointer to the start of the array.
#[allow(trivial_casts)]
pub const fn as_ptr(&self) -> *const T {
self as *const Self as *const T
ptr::from_ref::<Self>(self).cast::<T>()
}

/// Returns a mutable pointer to the start of the array.
#[allow(trivial_casts)]
pub const fn as_mut_ptr(&mut self) -> *mut T {
self as *mut Self as *mut T
ptr::from_mut::<Self>(self).cast::<T>()
}

/// Returns an iterator over the array.
Expand Down Expand Up @@ -358,6 +361,9 @@ where
}

/// Obtain a flattened slice from a slice of array chunks.
///
/// # Panics
/// - if the length calculation for the flattened slice overflows
#[inline]
pub const fn slice_as_flattened(slice: &[Self]) -> &[T] {
let len = slice
Expand All @@ -371,6 +377,9 @@ where
}

/// Obtain a mutable flattened slice from a mutable slice of array chunks.
///
/// # Panics
/// - if the length calculation for the flattened slice overflows
#[inline]
pub const fn slice_as_flattened_mut(slice: &mut [Self]) -> &mut [T] {
let len = slice
Expand Down Expand Up @@ -492,6 +501,7 @@ where
U: ArraySize,
{
/// Create an uninitialized array of [`MaybeUninit`]s for the given type.
#[must_use]
pub const fn uninit() -> Array<MaybeUninit<T>, U> {
// SAFETY: `Array` is a `repr(transparent)` newtype for `[MaybeUninit<T>, N]`, i.e. an
// array of uninitialized memory mediated via the `MaybeUninit` interface, where the inner
Expand Down Expand Up @@ -1082,7 +1092,7 @@ where

fn conditional_assign(&mut self, other: &Self, choice: Choice) {
for (a_i, b_i) in self.iter_mut().zip(other) {
a_i.conditional_assign(b_i, choice)
a_i.conditional_assign(b_i, choice);
}
}
}
Expand All @@ -1109,7 +1119,7 @@ where
{
#[inline]
fn zeroize(&mut self) {
self.0.as_mut().iter_mut().zeroize()
self.0.as_mut().iter_mut().zeroize();
}
}

Expand Down