Made ArrayVec::new and ArrayString::new const fns
Added utils module with a `MaybeUninit` helper type to construct `[MaybeUninit<T>; N]` Removed all uses of the "unstable-const-fn" feature, and documented it as being deprecated. Changed `assert_capacity_limit` macro to work in const contexts.
This commit is contained in:
+2
-12
@@ -23,6 +23,7 @@ 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.
|
||||
///
|
||||
@@ -76,20 +77,9 @@ impl<T, const CAP: usize> ArrayVec<T, CAP> {
|
||||
/// assert_eq!(&array[..], &[1, 2]);
|
||||
/// assert_eq!(array.capacity(), 16);
|
||||
/// ```
|
||||
#[cfg(not(feature="unstable-const-fn"))]
|
||||
pub fn new() -> ArrayVec<T, CAP> {
|
||||
assert_capacity_limit!(CAP);
|
||||
unsafe {
|
||||
ArrayVec { xs: MaybeUninit::uninit().assume_init(), len: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature="unstable-const-fn")]
|
||||
pub const fn new() -> ArrayVec<T, CAP> {
|
||||
assert_capacity_limit!(CAP);
|
||||
unsafe {
|
||||
ArrayVec { xs: MaybeUninit::uninit().assume_init(), len: 0 }
|
||||
}
|
||||
ArrayVec { xs: MakeMaybeUninit::ARRAY, len: 0 }
|
||||
}
|
||||
|
||||
/// Return the number of elements in the `ArrayVec`.
|
||||
|
||||
Reference in New Issue
Block a user