Update arrayvec to 0.7.6
Bug: http://b/339424309, http://b/367707312
Test: treehugger
Change-Id: I3b8b7bda346ecdc3045a165f1ed14c8a4082c2ef
diff --git a/crates/arrayvec/.cargo-checksum.json b/crates/arrayvec/.cargo-checksum.json
index f7b6795..2d1d47b 100644
--- a/crates/arrayvec/.cargo-checksum.json
+++ b/crates/arrayvec/.cargo-checksum.json
@@ -1 +1 @@
-{"files":{"CHANGELOG.md":"fc3afac61cfb6ed0370d35d8b7a01a9a4c43f07080ca6d7f4ed0ec5ffa1938a5","Cargo.toml":"bc1eb1e01f42009ada105cdcf8210471c9f988274a8e3874a362d169e90673dd","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"4da95ec4ecb65b738d470b7d762894ad9c97da93e6cbfb18b570fc2c96f4b871","README.md":"2264c34c62ea4c617d72047b00749b4786dfb9dff2fac24e0320170ee0cd19c8","benches/arraystring.rs":"fad1cecef71c290375befc77c75a868988b8d74135e8f8732bc5b58c85a8ab46","benches/extend.rs":"c38ecedbc88217a7e9fe1a73f916b168a96e48010a7ccd3dba5c3f8dea030d5d","src/array_string.rs":"39d9c33cdd3ec76e3dfd81996872c58d720877ef93fa7e8b23985d266230a2d6","src/arrayvec.rs":"50e2097cdfa4f1477c925daaf53cc7d59b31c66d11c0766cc1cbf14dad9dbc98","src/arrayvec_impl.rs":"e2642ae566c83ef37ad9aec6af7e3c50af310ba304553f38b2a787666b507580","src/char.rs":"1de50e1d6045af2b3496426492315ba774986f9bc8301ffa391de861a08cc9cb","src/errors.rs":"7fa2ff2350f811d52a210a7346c526d6715cacefd38a46e2d3b57ab7dc62b1ab","src/lib.rs":"8919a7e0c20890b1f094996147a1486d20578579aef03692315cd509e1745222","src/utils.rs":"d1cdc508dfca385e63f1f57bc8b53ed4a7f515e4ac1ebaa97b1d543fc8369432","tests/serde.rs":"117eb2961b5954d13c577edf60bbb07cb7481685cc9d6c49760a981d71465849","tests/tests.rs":"f8a18ff5deadb167832964ca0fff4f280129dd4a1de024e9cc76ffb7efe1c12c"},"package":"96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"}
\ No newline at end of file
+{"files":{"CHANGELOG.md":"b6cd865fb2685cf241e61f216686c87fd78e7d4b8ba4faf03857c8a2b920eee6","Cargo.toml":"ed90cef00235d8e2b9a3027e11baed38b66a2cf6003bccd805c056c1ec70c722","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"4da95ec4ecb65b738d470b7d762894ad9c97da93e6cbfb18b570fc2c96f4b871","README.md":"2264c34c62ea4c617d72047b00749b4786dfb9dff2fac24e0320170ee0cd19c8","benches/arraystring.rs":"fad1cecef71c290375befc77c75a868988b8d74135e8f8732bc5b58c85a8ab46","benches/extend.rs":"c38ecedbc88217a7e9fe1a73f916b168a96e48010a7ccd3dba5c3f8dea030d5d","src/array_string.rs":"9840c5b95af997584374467dfc365e4ab747175db8e0574be4f148454514fc8f","src/arrayvec.rs":"42923c20659346e48fd551529cb58b8e646c404637818ba466455665cb037dc4","src/arrayvec_impl.rs":"e2642ae566c83ef37ad9aec6af7e3c50af310ba304553f38b2a787666b507580","src/char.rs":"1de50e1d6045af2b3496426492315ba774986f9bc8301ffa391de861a08cc9cb","src/errors.rs":"7fa2ff2350f811d52a210a7346c526d6715cacefd38a46e2d3b57ab7dc62b1ab","src/lib.rs":"8919a7e0c20890b1f094996147a1486d20578579aef03692315cd509e1745222","src/utils.rs":"d1cdc508dfca385e63f1f57bc8b53ed4a7f515e4ac1ebaa97b1d543fc8369432","tests/borsh.rs":"4ea4d21cc311d68d8f234cd77699a88158af26cbc3a69ae1f25c0052663f861d","tests/serde.rs":"117eb2961b5954d13c577edf60bbb07cb7481685cc9d6c49760a981d71465849","tests/tests.rs":"19a9bce4b55506be9ffb7584f47dbfb1d59c66dbfaab55b7a28d827cc0411e78"},"package":"7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"}
\ No newline at end of file
diff --git a/crates/arrayvec/Android.bp b/crates/arrayvec/Android.bp
index 7c3a795..d69cb26 100644
--- a/crates/arrayvec/Android.bp
+++ b/crates/arrayvec/Android.bp
@@ -18,7 +18,7 @@
host_supported: true,
crate_name: "arrayvec",
cargo_env_compat: true,
- cargo_pkg_version: "0.7.4",
+ cargo_pkg_version: "0.7.6",
crate_root: "src/lib.rs",
test_suites: ["general-tests"],
auto_gen_config: true,
@@ -42,7 +42,7 @@
host_supported: true,
crate_name: "tests",
cargo_env_compat: true,
- cargo_pkg_version: "0.7.4",
+ cargo_pkg_version: "0.7.6",
crate_root: "tests/tests.rs",
test_suites: ["general-tests"],
auto_gen_config: true,
@@ -67,7 +67,7 @@
host_supported: true,
crate_name: "arrayvec",
cargo_env_compat: true,
- cargo_pkg_version: "0.7.4",
+ cargo_pkg_version: "0.7.6",
crate_root: "src/lib.rs",
edition: "2018",
features: [
diff --git a/crates/arrayvec/CHANGELOG.md b/crates/arrayvec/CHANGELOG.md
index 40a646a..056e6c0 100644
--- a/crates/arrayvec/CHANGELOG.md
+++ b/crates/arrayvec/CHANGELOG.md
@@ -1,6 +1,21 @@
Recent Changes (arrayvec)
=========================
+## 0.7.6
+
+- Fix no-std build [#274](https://github.com/bluss/arrayvec/pull/274)
+
+## 0.7.5
+
+- Add `as_ptr` and `as_mut_ptr` to `ArrayString` [@YuhanLiin](https://github.com/YuhanLiin) [#260](https://github.com/bluss/arrayvec/pull/260)
+- Add borsh serialization support by @honzasp and @Fuuzetsu [#259](https://github.com/bluss/arrayvec/pull/259)
+- Move length field before before data in ArrayVec and ArrayString by @JakkuSakura [#255](https://github.com/bluss/arrayvec/pull/255)
+- Fix miri error for ZST case in extend by @bluss
+- implement AsRef<Path> for ArrayString by [@Zoybean](https://github.com/Zoybean) [#218](https://github.com/bluss/arrayvec/pull/218)
+- Fix typos in changelog by [@striezel](https://github.com/striezel) [#241](https://github.com/bluss/arrayvec/pull/241)
+- Add `as_slice`, `as_mut_slice` methods to `IntoIter` by [@clarfonthey](https://github.com/clarfonthey) [#224](https://github.com/bluss/arrayvec/pull/224)
+
+
## 0.7.4
- Add feature zeroize to support the `Zeroize` trait by @elichai
@@ -118,7 +133,7 @@
users outside the crate.
- Add `FromStr` impl for `ArrayString` by @despawnerer
- Add method `try_extend_from_slice` to `ArrayVec`, which is always
- effecient by @Thomasdezeeuw.
+ efficient by @Thomasdezeeuw.
- Add method `remaining_capacity` by @Thomasdezeeuw
- Improve performance of the `extend` method.
- The index type of zero capacity vectors is now itself zero size, by
@@ -169,7 +184,7 @@
- Fix future compat warning about raw pointer casts
- Use `drop_in_place` when dropping the arrayvec by-value iterator
- - Decrease mininum Rust version (see docs) by @jeehoonkang
+ - Decrease minimum Rust version (see docs) by @jeehoonkang
- 0.3.25
diff --git a/crates/arrayvec/Cargo.toml b/crates/arrayvec/Cargo.toml
index 308c6b2..64c5392 100644
--- a/crates/arrayvec/Cargo.toml
+++ b/crates/arrayvec/Cargo.toml
@@ -11,9 +11,15 @@
[package]
edition = "2018"
+rust-version = "1.51"
name = "arrayvec"
-version = "0.7.4"
+version = "0.7.6"
authors = ["bluss"]
+build = false
+autobins = false
+autoexamples = false
+autotests = false
+autobenches = false
description = "A vector with fixed capacity, backed by an array (it can be stored on the stack too). Implements fixed capacity ArrayVec and ArrayString."
documentation = "https://docs.rs/arrayvec/"
readme = "README.md"
@@ -33,6 +39,7 @@
[package.metadata.docs.rs]
features = [
+ "borsh",
"serde",
"zeroize",
]
@@ -47,14 +54,37 @@
[profile.release]
debug = 2
-[[bench]]
-name = "extend"
-harness = false
+[lib]
+name = "arrayvec"
+path = "src/lib.rs"
+
+[[test]]
+name = "borsh"
+path = "tests/borsh.rs"
+
+[[test]]
+name = "serde"
+path = "tests/serde.rs"
+
+[[test]]
+name = "tests"
+path = "tests/tests.rs"
[[bench]]
name = "arraystring"
+path = "benches/arraystring.rs"
harness = false
+[[bench]]
+name = "extend"
+path = "benches/extend.rs"
+harness = false
+
+[dependencies.borsh]
+version = "1.2.0"
+optional = true
+default-features = false
+
[dependencies.serde]
version = "1.0"
optional = true
diff --git a/crates/arrayvec/METADATA b/crates/arrayvec/METADATA
index c4a014e..0c119b3 100644
--- a/crates/arrayvec/METADATA
+++ b/crates/arrayvec/METADATA
@@ -1,20 +1,17 @@
name: "arrayvec"
description: "A vector with fixed capacity, backed by an array (it can be stored on the stack too). Implements fixed capacity ArrayVec and ArrayString."
third_party {
- identifier {
- type: "crates.io"
- value: "https://crates.io/crates/arrayvec"
- }
- identifier {
- type: "Archive"
- value: "https://static.crates.io/crates/arrayvec/arrayvec-0.7.4.crate"
- }
- version: "0.7.4"
- # Dual-licensed, using the least restrictive per go/thirdpartylicenses#same.
+ version: "0.7.6"
license_type: NOTICE
last_upgrade_date {
- year: 2023
- month: 12
- day: 7
+ year: 2024
+ month: 9
+ day: 18
+ }
+ homepage: "https://crates.io/crates/arrayvec"
+ identifier {
+ type: "Archive"
+ value: "https://static.crates.io/crates/arrayvec/arrayvec-0.7.6.crate"
+ version: "0.7.6"
}
}
diff --git a/crates/arrayvec/src/array_string.rs b/crates/arrayvec/src/array_string.rs
index 90cfc09..6833237 100644
--- a/crates/arrayvec/src/array_string.rs
+++ b/crates/arrayvec/src/array_string.rs
@@ -5,6 +5,8 @@
use std::hash::{Hash, Hasher};
use std::mem::MaybeUninit;
use std::ops::{Deref, DerefMut};
+#[cfg(feature="std")]
+use std::path::Path;
use std::ptr;
use std::slice;
use std::str;
@@ -31,10 +33,11 @@
/// The string is a contiguous value that you can store directly on the stack
/// if needed.
#[derive(Copy)]
+#[repr(C)]
pub struct ArrayString<const CAP: usize> {
// the `len` first elements of the array are initialized
- xs: [MaybeUninit<u8>; CAP],
len: LenUint,
+ xs: [MaybeUninit<u8>; CAP],
}
impl<const CAP: usize> Default for ArrayString<CAP>
@@ -414,11 +417,13 @@
self
}
- fn as_ptr(&self) -> *const u8 {
+ /// Return a raw pointer to the string's buffer.
+ pub fn as_ptr(&self) -> *const u8 {
self.xs.as_ptr() as *const u8
}
- fn as_mut_ptr(&mut self) -> *mut u8 {
+ /// Return a raw mutable pointer to the string's buffer.
+ pub fn as_mut_ptr(&mut self) -> *mut u8 {
self.xs.as_mut_ptr() as *mut u8
}
}
@@ -498,6 +503,13 @@
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { (**self).fmt(f) }
}
+#[cfg(feature="std")]
+impl<const CAP: usize> AsRef<Path> for ArrayString<CAP> {
+ fn as_ref(&self) -> &Path {
+ self.as_str().as_ref()
+ }
+}
+
impl<const CAP: usize> fmt::Display for ArrayString<CAP>
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { (**self).fmt(f) }
@@ -625,6 +637,37 @@
}
}
+#[cfg(feature = "borsh")]
+/// Requires crate feature `"borsh"`
+impl<const CAP: usize> borsh::BorshSerialize for ArrayString<CAP> {
+ fn serialize<W: borsh::io::Write>(&self, writer: &mut W) -> borsh::io::Result<()> {
+ <str as borsh::BorshSerialize>::serialize(&*self, writer)
+ }
+}
+
+#[cfg(feature = "borsh")]
+/// Requires crate feature `"borsh"`
+impl<const CAP: usize> borsh::BorshDeserialize for ArrayString<CAP> {
+ fn deserialize_reader<R: borsh::io::Read>(reader: &mut R) -> borsh::io::Result<Self> {
+ let len = <u32 as borsh::BorshDeserialize>::deserialize_reader(reader)? as usize;
+ if len > CAP {
+ return Err(borsh::io::Error::new(
+ borsh::io::ErrorKind::InvalidData,
+ format!("Expected a string no more than {} bytes long", CAP),
+ ))
+ }
+
+ let mut buf = [0u8; CAP];
+ let buf = &mut buf[..len];
+ reader.read_exact(buf)?;
+
+ let s = str::from_utf8(&buf).map_err(|err| {
+ borsh::io::Error::new(borsh::io::ErrorKind::InvalidData, err.to_string())
+ })?;
+ Ok(Self::from(s).unwrap())
+ }
+}
+
impl<'a, const CAP: usize> TryFrom<&'a str> for ArrayString<CAP>
{
type Error = CapacityError<&'a str>;
diff --git a/crates/arrayvec/src/arrayvec.rs b/crates/arrayvec/src/arrayvec.rs
index 37e151a..e87b3ef 100644
--- a/crates/arrayvec/src/arrayvec.rs
+++ b/crates/arrayvec/src/arrayvec.rs
@@ -39,10 +39,11 @@
///
/// It offers a simple API but also dereferences to a slice, so that the full slice API is
/// available. The ArrayVec can be converted into a by value iterator.
+#[repr(C)]
pub struct ArrayVec<T, const CAP: usize> {
+ len: LenUint,
// the `len` first elements of the array are initialized
xs: [MaybeUninit<T>; CAP],
- len: LenUint,
}
impl<T, const CAP: usize> Drop for ArrayVec<T, CAP> {
@@ -879,6 +880,17 @@
index: usize,
v: ArrayVec<T, CAP>,
}
+impl<T, const CAP: usize> IntoIter<T, CAP> {
+ /// Returns the remaining items of this iterator as a slice.
+ pub fn as_slice(&self) -> &[T] {
+ &self.v[self.index..]
+ }
+
+ /// Returns the remaining items of this iterator as a mutable slice.
+ pub fn as_mut_slice(&mut self) -> &mut [T] {
+ &mut self.v[self.index..]
+ }
+}
impl<T, const CAP: usize> Iterator for IntoIter<T, CAP> {
type Item = T;
@@ -1088,7 +1100,9 @@
if let Some(elt) = iter.next() {
if ptr == end_ptr && CHECK { extend_panic(); }
debug_assert_ne!(ptr, end_ptr);
- ptr.write(elt);
+ if mem::size_of::<T>() != 0 {
+ ptr.write(elt);
+ }
ptr = raw_ptr_add(ptr, 1);
guard.data += 1;
} else {
@@ -1115,7 +1129,7 @@
unsafe fn raw_ptr_add<T>(ptr: *mut T, offset: usize) -> *mut T {
if mem::size_of::<T>() == 0 {
// Special case for ZST
- ptr.cast::<u8>().wrapping_add(offset).cast()
+ ptr.cast::<u8>().wrapping_add(offset).cast::<T>()
} else {
ptr.add(offset)
}
@@ -1298,3 +1312,37 @@
deserializer.deserialize_seq(ArrayVecVisitor::<T, CAP>(PhantomData))
}
}
+
+#[cfg(feature = "borsh")]
+/// Requires crate feature `"borsh"`
+impl<T, const CAP: usize> borsh::BorshSerialize for ArrayVec<T, CAP>
+where
+ T: borsh::BorshSerialize,
+{
+ fn serialize<W: borsh::io::Write>(&self, writer: &mut W) -> borsh::io::Result<()> {
+ <[T] as borsh::BorshSerialize>::serialize(self.as_slice(), writer)
+ }
+}
+
+#[cfg(feature = "borsh")]
+/// Requires crate feature `"borsh"`
+impl<T, const CAP: usize> borsh::BorshDeserialize for ArrayVec<T, CAP>
+where
+ T: borsh::BorshDeserialize,
+{
+ fn deserialize_reader<R: borsh::io::Read>(reader: &mut R) -> borsh::io::Result<Self> {
+ let mut values = Self::new();
+ let len = <u32 as borsh::BorshDeserialize>::deserialize_reader(reader)?;
+ for _ in 0..len {
+ let elem = <T as borsh::BorshDeserialize>::deserialize_reader(reader)?;
+ if let Err(_) = values.try_push(elem) {
+ return Err(borsh::io::Error::new(
+ borsh::io::ErrorKind::InvalidData,
+ format!("Expected an array with no more than {} items", CAP),
+ ));
+ }
+ }
+
+ Ok(values)
+ }
+}
diff --git a/crates/arrayvec/tests/borsh.rs b/crates/arrayvec/tests/borsh.rs
new file mode 100644
index 0000000..f05abcf
--- /dev/null
+++ b/crates/arrayvec/tests/borsh.rs
@@ -0,0 +1,73 @@
+#![cfg(feature = "borsh")]
+use std::fmt;
+extern crate arrayvec;
+extern crate borsh;
+
+fn assert_ser<T: borsh::BorshSerialize>(v: &T, expected_bytes: &[u8]) {
+ let mut actual_bytes = Vec::new();
+ v.serialize(&mut actual_bytes).unwrap();
+ assert_eq!(actual_bytes, expected_bytes);
+}
+
+fn assert_roundtrip<T: borsh::BorshSerialize + borsh::BorshDeserialize + PartialEq + fmt::Debug>(v: &T) {
+ let mut bytes = Vec::new();
+ v.serialize(&mut bytes).unwrap();
+ let v_de = T::try_from_slice(&bytes).unwrap();
+ assert_eq!(*v, v_de);
+}
+
+mod array_vec {
+ use arrayvec::ArrayVec;
+ use super::{assert_ser, assert_roundtrip};
+
+ #[test]
+ fn test_empty() {
+ let vec = ArrayVec::<u32, 0>::new();
+ assert_ser(&vec, b"\0\0\0\0");
+ assert_roundtrip(&vec);
+ }
+
+ #[test]
+ fn test_full() {
+ let mut vec = ArrayVec::<u32, 3>::new();
+ vec.push(0xdeadbeef);
+ vec.push(0x123);
+ vec.push(0x456);
+ assert_ser(&vec, b"\x03\0\0\0\xef\xbe\xad\xde\x23\x01\0\0\x56\x04\0\0");
+ assert_roundtrip(&vec);
+ }
+
+ #[test]
+ fn test_with_free_capacity() {
+ let mut vec = ArrayVec::<u32, 3>::new();
+ vec.push(0xdeadbeef);
+ assert_ser(&vec, b"\x01\0\0\0\xef\xbe\xad\xde");
+ assert_roundtrip(&vec);
+ }
+}
+
+mod array_string {
+ use arrayvec::ArrayString;
+ use super::{assert_ser, assert_roundtrip};
+
+ #[test]
+ fn test_empty() {
+ let string = ArrayString::<0>::new();
+ assert_ser(&string, b"\0\0\0\0");
+ assert_roundtrip(&string);
+ }
+
+ #[test]
+ fn test_full() {
+ let string = ArrayString::from_byte_string(b"hello world").unwrap();
+ assert_ser(&string, b"\x0b\0\0\0hello world");
+ assert_roundtrip(&string);
+ }
+
+ #[test]
+ fn test_with_free_capacity() {
+ let string = ArrayString::<16>::from("hello world").unwrap();
+ assert_ser(&string, b"\x0b\0\0\0hello world");
+ assert_roundtrip(&string);
+ }
+}
diff --git a/crates/arrayvec/tests/tests.rs b/crates/arrayvec/tests/tests.rs
index 2f8a5ef..16508b7 100644
--- a/crates/arrayvec/tests/tests.rs
+++ b/crates/arrayvec/tests/tests.rs
@@ -695,20 +695,6 @@
assert_eq!(v.len(), 0);
}
-#[cfg(feature="array-sizes-33-128")]
-#[test]
-fn test_sizes_33_128() {
- ArrayVec::from([0u8; 52]);
- ArrayVec::from([0u8; 127]);
-}
-
-#[cfg(feature="array-sizes-129-255")]
-#[test]
-fn test_sizes_129_255() {
- ArrayVec::from([0u8; 237]);
- ArrayVec::from([0u8; 255]);
-}
-
#[test]
fn test_extend_zst() {
let mut range = 0..10;
@@ -790,4 +776,4 @@
let string = ArrayString::<4>::zero_filled();
assert_eq!(string.as_str(), "\0\0\0\0");
assert_eq!(string.len(), 4);
-}
\ No newline at end of file
+}
diff --git a/pseudo_crate/Cargo.lock b/pseudo_crate/Cargo.lock
index 0429efc..b854378 100644
--- a/pseudo_crate/Cargo.lock
+++ b/pseudo_crate/Cargo.lock
@@ -349,9 +349,9 @@
[[package]]
name = "arrayvec"
-version = "0.7.4"
+version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
+checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
[[package]]
name = "ash"
diff --git a/pseudo_crate/Cargo.toml b/pseudo_crate/Cargo.toml
index 9642047..c2c35da 100644
--- a/pseudo_crate/Cargo.toml
+++ b/pseudo_crate/Cargo.toml
@@ -16,7 +16,7 @@
argh = "=0.1.12"
argh_derive = "=0.1.12"
argh_shared = "=0.1.12"
-arrayvec = "=0.7.4"
+arrayvec = "=0.7.6"
ash = "=0.37.3"
async-stream = "=0.3.5"
async-stream-impl = "=0.3.5"