Skip to content
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

Pr arrayvec copy edit #281

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Make ArrayVecCopy functions non-const
They don't work on Rust 1.51

```
error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable
  --> src/arrayvec_copy.rs:59:6
   |
59 | impl<T: Copy, const CAP: usize> ArrayVecCopy<T, CAP> {
   |      ^
   |
   = note: see issue #57563 <rust-lang/rust#57563> for more information
   = help: add `#![feature(const_fn)]` to the crate attributes to enable
```
  • Loading branch information
tbu- committed Oct 17, 2024
commit 6a182a2153d0fddf6d0c686c824570ac6747c371
1 change: 1 addition & 0 deletions generate_arrayvec_copy
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ sed \
-e "s/struct \\([A-Za-z_]*\\)<\\('[A-Za-z_]*, \\)\\?T,/struct \\1<\\2T: Copy,/g" \
-e "s/fn \\([A-Za-z_]*\\)<\\('[A-Za-z_]*, \\)\\?T:/fn \\1<\\2T: Copy +/g" \
-e "s/fn \\([A-Za-z_]*\\)<\\('[A-Za-z_]*, \\)\\?T,/fn \\1<\\2T: Copy,/g" \
-e "s/const fn/fn/" \
src/arrayvec.rs \
> src/arrayvec_copy_generated.rs

33 changes: 29 additions & 4 deletions src/arrayvec_copy.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
diff --git a/src/arrayvec_copy_generated.rs b/src/arrayvec_copy.rs
index b12aa9e..5597af9 100644
index f61b5b3..fab45ec 100644
--- a/src/arrayvec_copy_generated.rs
+++ b/src/arrayvec_copy.rs
@@ -27,6 +27,9 @@ use crate::utils::MakeMaybeUninit;
@@ -23,10 +23,12 @@ use serde::{Serialize, Deserialize, Serializer, Deserializer};
use crate::LenUint;
use crate::errors::CapacityError;
use crate::arrayvec_impl::ArrayVecImpl;
-use crate::utils::MakeMaybeUninit;

/// A vector with a fixed capacity.
///
@@ -12,7 +16,7 @@ index b12aa9e..5597af9 100644
/// The `ArrayVecCopy` is a vector backed by a fixed size array. It keeps track of
/// the number of initialized elements. The `ArrayVecCopy<T, CAP>` is parameterized
/// by `T` for the element type and `CAP` for the maximum capacity.
@@ -46,14 +49,6 @@ pub struct ArrayVecCopy<T: Copy, const CAP: usize> {
@@ -46,14 +48,6 @@ pub struct ArrayVecCopy<T: Copy, const CAP: usize> {
xs: [MaybeUninit<T>; CAP],
}

@@ -27,7 +31,28 @@ index b12aa9e..5597af9 100644
macro_rules! panic_oob {
($method_name:expr, $index:expr, $len:expr) => {
panic!(concat!("ArrayVecCopy::", $method_name, ": index {} is out of bounds in vector of length {}"),
@@ -964,21 +959,6 @@ impl<T: Copy, const CAP: usize> DoubleEndedIterator for IntoIter<T, CAP> {
@@ -87,20 +81,6 @@ impl<T: Copy, const CAP: usize> ArrayVecCopy<T, CAP> {
}
}

- /// Create a new empty `ArrayVecCopy` (fn).
- ///
- /// The maximum capacity is given by the generic parameter `CAP`.
- ///
- /// ```
- /// use arrayvec::ArrayVecCopy;
- ///
- /// static ARRAY: ArrayVecCopy<u8, 1024> = ArrayVecCopy::new_const();
- /// ```
- pub fn new_const() -> ArrayVecCopy<T, CAP> {
- assert_capacity_limit_const!(CAP);
- ArrayVecCopy { xs: MakeMaybeUninit::ARRAY, len: 0 }
- }
-
/// Return the number of elements in the `ArrayVecCopy`.
///
/// ```
@@ -964,21 +944,6 @@ impl<T: Copy, const CAP: usize> DoubleEndedIterator for IntoIter<T, CAP> {

impl<T: Copy, const CAP: usize> ExactSizeIterator for IntoIter<T, CAP> { }

25 changes: 5 additions & 20 deletions src/arrayvec_copy.rs
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@ use serde::{Serialize, Deserialize, Serializer, Deserializer};
use crate::LenUint;
use crate::errors::CapacityError;
use crate::arrayvec_impl::ArrayVecImpl;
use crate::utils::MakeMaybeUninit;

/// A vector with a fixed capacity.
///
@@ -82,20 +81,6 @@ impl<T: Copy, const CAP: usize> ArrayVecCopy<T, CAP> {
}
}

/// Create a new empty `ArrayVecCopy` (const fn).
///
/// The maximum capacity is given by the generic parameter `CAP`.
///
/// ```
/// use arrayvec::ArrayVecCopy;
///
/// static ARRAY: ArrayVecCopy<u8, 1024> = ArrayVecCopy::new_const();
/// ```
pub const fn new_const() -> ArrayVecCopy<T, CAP> {
assert_capacity_limit_const!(CAP);
ArrayVecCopy { xs: MakeMaybeUninit::ARRAY, len: 0 }
}

/// Return the number of elements in the `ArrayVecCopy`.
///
/// ```
@@ -106,7 +91,7 @@ impl<T: Copy, const CAP: usize> ArrayVecCopy<T, CAP> {
/// assert_eq!(array.len(), 2);
/// ```
#[inline(always)]
pub const fn len(&self) -> usize { self.len as usize }
pub fn len(&self) -> usize { self.len as usize }

/// Returns whether the `ArrayVecCopy` is empty.
///
@@ -118,7 +103,7 @@ impl<T: Copy, const CAP: usize> ArrayVecCopy<T, CAP> {
/// assert_eq!(array.is_empty(), true);
/// ```
#[inline]
pub const fn is_empty(&self) -> bool { self.len() == 0 }
pub fn is_empty(&self) -> bool { self.len() == 0 }

/// Return the capacity of the `ArrayVecCopy`.
///
@@ -129,7 +114,7 @@ impl<T: Copy, const CAP: usize> ArrayVecCopy<T, CAP> {
/// assert_eq!(array.capacity(), 3);
/// ```
#[inline(always)]
pub const fn capacity(&self) -> usize { CAP }
pub fn capacity(&self) -> usize { CAP }

/// Return true if the `ArrayVecCopy` is completely filled to its capacity, false otherwise.
///
@@ -141,7 +126,7 @@ impl<T: Copy, const CAP: usize> ArrayVecCopy<T, CAP> {
/// array.push(1);
/// assert!(array.is_full());
/// ```
pub const fn is_full(&self) -> bool { self.len() == self.capacity() }
pub fn is_full(&self) -> bool { self.len() == self.capacity() }

/// Returns the capacity left in the `ArrayVecCopy`.
///
@@ -152,7 +137,7 @@ impl<T: Copy, const CAP: usize> ArrayVecCopy<T, CAP> {
/// array.pop();
/// assert_eq!(array.remaining_capacity(), 1);
/// ```
pub const fn remaining_capacity(&self) -> usize {
pub fn remaining_capacity(&self) -> usize {
self.capacity() - self.len()
}