FIX: Add new_const() for const construction and revert new to old version

The new() function is significantly faster, it optimizes better at the
moment/in current rust. For this reason, provide a const fn constructor,
but not as the default `new`.
This commit is contained in:
bluss
2021-03-29 21:45:37 +02:00
parent 198a403194
commit b7f3aa9fce
4 changed files with 65 additions and 6 deletions
+14 -4
View File
@@ -718,19 +718,29 @@ fn allow_max_capacity_arrayvec_type() {
let _v: ArrayVec<(), {usize::MAX}>;
}
#[should_panic(expected="index out of bounds")]
#[should_panic(expected="largest supported capacity")]
#[test]
fn deny_max_capacity_arrayvec_value() {
if mem::size_of::<usize>() <= mem::size_of::<u32>() {
panic!("This test does not work on this platform. 'index out of bounds'");
panic!("This test does not work on this platform. 'largest supported capacity'");
}
// this type is allowed to be used (but can't be constructed)
let _v: ArrayVec<(), {usize::MAX}> = ArrayVec::new();
}
#[should_panic(expected="index out of bounds")]
#[test]
fn deny_max_capacity_arrayvec_value_const() {
if mem::size_of::<usize>() <= mem::size_of::<u32>() {
panic!("This test does not work on this platform. 'index out of bounds'");
}
// this type is allowed to be used (but can't be constructed)
let _v: ArrayVec<(), {usize::MAX}> = ArrayVec::new_const();
}
#[test]
fn test_arrayvec_const_constructible() {
const OF_U8: ArrayVec<Vec<u8>, 10> = ArrayVec::new();
const OF_U8: ArrayVec<Vec<u8>, 10> = ArrayVec::new_const();
let mut var = OF_U8;
assert!(var.is_empty());
@@ -742,7 +752,7 @@ fn test_arrayvec_const_constructible() {
#[test]
fn test_arraystring_const_constructible() {
const AS: ArrayString<10> = ArrayString::new();
const AS: ArrayString<10> = ArrayString::new_const();
let mut var = AS;
assert!(var.is_empty());