Use 16-bit lengths on 16-bit targets
This commit is contained in:
+2
-2
@@ -27,8 +27,8 @@ use serde::{Serialize, Deserialize, Serializer, Deserializer};
|
|||||||
/// The `ArrayString` is a string backed by a fixed size array. It keeps track
|
/// The `ArrayString` is a string backed by a fixed size array. It keeps track
|
||||||
/// of its length, and is parameterized by `CAP` for the maximum capacity.
|
/// of its length, and is parameterized by `CAP` for the maximum capacity.
|
||||||
///
|
///
|
||||||
/// `CAP` is of type `usize` but is range limited to `u32::MAX`; attempting to create larger
|
/// `CAP` is of type `usize` but is range limited to `u32::MAX` (or `u16` on 16-bit targets);
|
||||||
/// arrayvecs with larger capacity will panic.
|
/// attempting to create larger arrayvecs with larger capacity will panic.
|
||||||
///
|
///
|
||||||
/// The string is a contiguous value that you can store directly on the stack
|
/// The string is a contiguous value that you can store directly on the stack
|
||||||
/// if needed.
|
/// if needed.
|
||||||
|
|||||||
+2
-2
@@ -31,8 +31,8 @@ use crate::utils::MakeMaybeUninit;
|
|||||||
/// the number of initialized elements. The `ArrayVec<T, CAP>` is parameterized
|
/// the number of initialized elements. The `ArrayVec<T, CAP>` is parameterized
|
||||||
/// by `T` for the element type and `CAP` for the maximum capacity.
|
/// by `T` for the element type and `CAP` for the maximum capacity.
|
||||||
///
|
///
|
||||||
/// `CAP` is of type `usize` but is range limited to `u32::MAX`; attempting to create larger
|
/// `CAP` is of type `usize` but is range limited to `u32::MAX` (or `u16::MAX` on 16-bit targets);
|
||||||
/// arrayvecs with larger capacity will panic.
|
/// attempting to create larger arrayvecs with larger capacity will panic.
|
||||||
///
|
///
|
||||||
/// The vector is a contiguous value (storing the elements inline) that you can store directly on
|
/// The vector is a contiguous value (storing the elements inline) that you can store directly on
|
||||||
/// the stack if needed.
|
/// the stack if needed.
|
||||||
|
|||||||
+8
-1
@@ -28,13 +28,20 @@ extern crate serde;
|
|||||||
#[cfg(not(feature="std"))]
|
#[cfg(not(feature="std"))]
|
||||||
extern crate core as std;
|
extern crate core as std;
|
||||||
|
|
||||||
|
#[cfg(not(target_pointer_width = "16"))]
|
||||||
pub(crate) type LenUint = u32;
|
pub(crate) type LenUint = u32;
|
||||||
|
|
||||||
|
#[cfg(target_pointer_width = "16")]
|
||||||
|
pub(crate) type LenUint = u16;
|
||||||
|
|
||||||
macro_rules! assert_capacity_limit {
|
macro_rules! assert_capacity_limit {
|
||||||
($cap:expr) => {
|
($cap:expr) => {
|
||||||
if std::mem::size_of::<usize>() > std::mem::size_of::<LenUint>() {
|
if std::mem::size_of::<usize>() > std::mem::size_of::<LenUint>() {
|
||||||
if $cap > LenUint::MAX as usize {
|
if $cap > LenUint::MAX as usize {
|
||||||
panic!("ArrayVec: largest supported capacity is u32::MAX")
|
#[cfg(not(target_pointer_width = "16"))]
|
||||||
|
panic!("ArrayVec: largest supported capacity is u32::MAX");
|
||||||
|
#[cfg(target_pointer_width = "16")]
|
||||||
|
panic!("ArrayVec: largest supported capacity is u16::MAX");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-6
@@ -680,6 +680,7 @@ fn test_pop_at() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg(not(target_pointer_width = "16"))]
|
||||||
fn test_sizes() {
|
fn test_sizes() {
|
||||||
let v = ArrayVec::from([0u8; 1 << 16]);
|
let v = ArrayVec::from([0u8; 1 << 16]);
|
||||||
assert_eq!(vec![0u8; v.len()], &v[..]);
|
assert_eq!(vec![0u8; v.len()], &v[..]);
|
||||||
@@ -729,21 +730,17 @@ fn allow_max_capacity_arrayvec_type() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[should_panic(expected="largest supported capacity")]
|
#[should_panic(expected="largest supported capacity")]
|
||||||
|
#[cfg(not(target_pointer_width = "16"))]
|
||||||
#[test]
|
#[test]
|
||||||
fn deny_max_capacity_arrayvec_value() {
|
fn deny_max_capacity_arrayvec_value() {
|
||||||
if mem::size_of::<usize>() <= mem::size_of::<u32>() {
|
|
||||||
panic!("This test does not work on this platform. 'largest supported capacity'");
|
|
||||||
}
|
|
||||||
// this type is allowed to be used (but can't be constructed)
|
// this type is allowed to be used (but can't be constructed)
|
||||||
let _v: ArrayVec<(), {usize::MAX}> = ArrayVec::new();
|
let _v: ArrayVec<(), {usize::MAX}> = ArrayVec::new();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[should_panic(expected="index out of bounds")]
|
#[should_panic(expected="index out of bounds")]
|
||||||
|
#[cfg(not(target_pointer_width = "16"))]
|
||||||
#[test]
|
#[test]
|
||||||
fn deny_max_capacity_arrayvec_value_const() {
|
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)
|
// this type is allowed to be used (but can't be constructed)
|
||||||
let _v: ArrayVec<(), {usize::MAX}> = ArrayVec::new_const();
|
let _v: ArrayVec<(), {usize::MAX}> = ArrayVec::new_const();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user