Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
novacrazy committed Sep 4, 2023
1 parent 7e45005 commit ff7a355
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* Add the `internals` Cargo feature to expose dangerous things.
* Added additional methods for working with chunks of arrays.
* Added `From` impls for tuples with 1-12 (inclusive) items of the same type, matching the standard library.
* Workaround potential Rust/LLVM regressions with `FunctionalSequence::zip()`/`::map()`
* Improve documentation

* **`0.14.6`**
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repository = "https://github.com/fizyk20/generic-array.git"

keywords = ["generic", "array"]
categories = ["data-structures", "no-std"]
include = ["src/**/*", "LICENSE", "README.md", "CHANGELOG.md", "build.rs"]
include = ["src/**/*", "LICENSE", "README.md", "CHANGELOG.md"]

[badges]
travis-ci = { repository = "fizyk20/generic-array" }
Expand Down
9 changes: 5 additions & 4 deletions src/impl_alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl<T, N: ArrayLength> TryFrom<Vec<T>> for GenericArray<T, N> {
impl<T, N: ArrayLength> GenericArray<T, N> {
/// Converts a `Box<GenericArray<T, N>>` into `Box<[T]>` without reallocating.
///
/// This operation is O(1)
/// This operation is O(1), constant-time regardless of the array length N.
#[inline]
pub fn into_boxed_slice(self: Box<GenericArray<T, N>>) -> Box<[T]> {
unsafe {
Expand All @@ -37,15 +37,15 @@ impl<T, N: ArrayLength> GenericArray<T, N> {

/// Converts a `Box<GenericArray<T, N>>` into `Vec<T>` without reallocating.
///
/// This operation is O(1)
/// This operation is O(1), constant-time regardless of the array length N.
#[inline]
pub fn into_vec(self: Box<GenericArray<T, N>>) -> Vec<T> {
Vec::from(self.into_boxed_slice())
}

/// Attempts to convert a `Box<[T]>` into `Box<GenericArray<T, N>>` without reallocating.
///
/// This operation is O(1)
/// This operation is O(1), constant-time regardless of the array length N.
#[inline]
pub fn try_from_boxed_slice(slice: Box<[T]>) -> Result<Box<GenericArray<T, N>>, LengthError> {
if slice.len() != N::USIZE {
Expand All @@ -58,7 +58,8 @@ impl<T, N: ArrayLength> GenericArray<T, N> {
/// Attempts to convert a `Vec<T>` into `Box<GenericArray<T, N>>` without reallocating.
///
/// This operation is O(1) **if the `Vec` has the same length and capacity as `N`**,
/// otherwise it will be forced to call `Vec::shrink_to_fit` which is O(N)
/// otherwise it will be forced to call `Vec::shrink_to_fit` which is O(N),
/// where N is the number of elements.
#[inline]
pub fn try_from_vec(vec: Vec<T>) -> Result<Box<GenericArray<T, N>>, LengthError> {
Self::try_from_boxed_slice(vec.into_boxed_slice())
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ where
let right_value = ptr::read(r);

*left_position += 1;
*right_position += 1;
*right_position = *left_position;

f(left_value, right_value)
}))
Expand Down Expand Up @@ -579,7 +579,7 @@ where

let (right_array_iter, right_position) = right.iter_position();

FromIterator::from_iter(right_array_iter.zip(lhs).map(move |(r, left_value)| {
FromIterator::from_iter(right_array_iter.zip(lhs).map(|(r, left_value)| {
let right_value = ptr::read(r);

*right_position += 1;
Expand Down
7 changes: 7 additions & 0 deletions tests/arr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,11 @@ fn alloc_arr() {

_ = box_arr![0; 12];
_ = box_arr![1; 't' as usize];

// ZSTs
_ = box_arr![0f32; 0].into_boxed_slice();
let z = box_arr![(); 5].into_boxed_slice();

#[allow(clippy::let_unit_value)]
let _ = z[0];
}

0 comments on commit ff7a355

Please sign in to comment.