diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-07-07 04:56:46 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-07-07 04:56:46 +0000 |
commit | 6080b00b1fd1ee6cd5f19d2f47f15f0b58ac505a (patch) | |
tree | b20f2866c1a76f13beb74f38d89e4f93290a0da8 | |
parent | be84cbd546b9db3a35617bfcf1f94a74a11090c9 (diff) | |
parent | a670ec81179294d145ffa702143a8ac479871f45 (diff) | |
download | tinyvec-aml_med_341619000.tar.gz |
Snap for 10453563 from a670ec81179294d145ffa702143a8ac479871f45 to mainline-media-releaseaml_med_341711000aml_med_341619000aml_med_341513600aml_med_341312300aml_med_341312020aml_med_341111000aml_med_341011000aml_med_340922010android14-mainline-media-release
Change-Id: I6f7aa28ce9ba5edbaf089398de35bfe736a04df7
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Android.bp | 57 | ||||
-rw-r--r-- | CHANGELOG.md | 8 | ||||
-rw-r--r-- | Cargo.toml | 54 | ||||
-rw-r--r-- | Cargo.toml.orig | 8 | ||||
-rw-r--r-- | METADATA | 12 | ||||
-rw-r--r-- | TEST_MAPPING | 9 | ||||
-rw-r--r-- | cargo2android.json | 3 | ||||
-rw-r--r-- | cargo2android_nostd.bp | 16 | ||||
-rw-r--r-- | patches/std.diff | 14 | ||||
-rw-r--r-- | src/arrayvec.rs | 63 | ||||
-rw-r--r-- | src/lib.rs | 3 | ||||
-rw-r--r-- | src/tinyvec.rs | 126 | ||||
-rw-r--r-- | tests/tinyvec.rs | 57 |
14 files changed, 381 insertions, 51 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 6772581..fcfc522 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,6 +1,6 @@ { "git": { - "sha1": "1ef53f632b9cb6f2e7ff603586f4472317b9a25c" + "sha1": "6e326cc48208229d1f28abf74a3e06944c8f7bec" }, "path_in_vcs": "" }
\ No newline at end of file @@ -44,12 +44,13 @@ rust_library { host_supported: true, crate_name: "tinyvec", cargo_env_compat: true, - cargo_pkg_version: "1.5.1", + cargo_pkg_version: "1.6.0", srcs: ["src/lib.rs"], edition: "2018", features: [ "alloc", "default", + "std", "tinyvec_macros", ], rustlibs: [ @@ -59,25 +60,23 @@ rust_library { "//apex_available:platform", "com.android.resolv", ], + product_available: true, + vendor_available: true, min_sdk_version: "29", } -rust_test { - name: "tinyvec_test_tests_arrayvec", - host_supported: true, - crate_name: "arrayvec", +rust_defaults { + name: "tinyvec_test_defaults", + crate_name: "tinyvec", cargo_env_compat: true, - cargo_pkg_version: "1.5.1", - srcs: ["tests/arrayvec.rs"], + cargo_pkg_version: "1.6.0", test_suites: ["general-tests"], auto_gen_config: true, - test_options: { - unit_test: true, - }, edition: "2018", features: [ "alloc", "default", + "std", "tinyvec_macros", ], rustlibs: [ @@ -88,3 +87,41 @@ rust_test { "libtinyvec_macros", ], } + +rust_test { + name: "tinyvec_test_tests_arrayvec", + defaults: ["tinyvec_test_defaults"], + host_supported: true, + srcs: ["tests/arrayvec.rs"], + test_options: { + unit_test: true, + }, +} + +rust_test { + name: "tinyvec_test_tests_tinyvec", + defaults: ["tinyvec_test_defaults"], + host_supported: true, + srcs: ["tests/tinyvec.rs"], + test_options: { + unit_test: true, + }, +} + +rust_library_rlib { + name: "libtinyvec_nostd", + crate_name: "tinyvec", + cargo_env_compat: true, + cargo_pkg_version: "1.5.1", + srcs: ["src/lib.rs"], + edition: "2018", + prefer_rlib: true, + no_stdlibs: true, + stdlibs: [ + "libcompiler_builtins.rust_sysroot", + "libcore.rust_sysroot", + ], + vendor_available: true, + min_sdk_version: "29", +} + diff --git a/CHANGELOG.md b/CHANGELOG.md index 93ef808..6f7d2c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog
+## 1.6.0
+
+* [i509VCB](https://github.com/i509VCB) added the `try_` functions for fallable reallocation.
+ [pr 158](https://github.com/Lokathor/tinyvec/pull/158)
+* [ajtribick](https://github.com/ajtribick) added more error impls to `TryFromSliceError`.
+ [pr 160](https://github.com/Lokathor/tinyvec/pull/160)
+* The `std` feature now automatically enables the `alloc` feature as well.
+
## 1.5.1
* [madsmtm](https://github.com/madsmtm) fixed an error with the `alloc` feature on very old rustc versions.
@@ -12,19 +12,46 @@ [package] edition = "2018" name = "tinyvec" -version = "1.5.1" +version = "1.6.0" authors = ["Lokathor <zefria@gmail.com>"] description = "`tinyvec` provides 100% safe vec-like data structures." -keywords = ["vec", "no_std", "no-std"] -categories = ["data-structures", "no-std"] +readme = "README.md" +keywords = [ + "vec", + "no_std", + "no-std", +] +categories = [ + "data-structures", + "no-std", +] license = "Zlib OR Apache-2.0 OR MIT" repository = "https://github.com/Lokathor/tinyvec" + [package.metadata.docs.rs] -features = ["alloc", "std", "grab_spare_slice", "rustc_1_40", "rustc_1_55", "serde"] -rustdoc-args = ["--cfg", "docs_rs"] +features = [ + "alloc", + "std", + "grab_spare_slice", + "rustc_1_40", + "rustc_1_55", + "serde", +] +rustdoc-args = [ + "--cfg", + "docs_rs", +] [package.metadata.playground] -features = ["alloc", "std", "grab_spare_slice", "rustc_1_40", "rustc_1_55", "serde"] +features = [ + "alloc", + "std", + "grab_spare_slice", + "rustc_1_40", + "rustc_1_55", + "serde", +] + [profile.bench] debug = 2 @@ -33,7 +60,10 @@ opt-level = 3 [[test]] name = "tinyvec" -required-features = ["alloc", "std"] +required-features = [ + "alloc", + "std", +] [[bench]] name = "macros" @@ -43,7 +73,11 @@ required-features = ["alloc"] [[bench]] name = "smallvec" harness = false -required-features = ["alloc", "real_blackbox"] +required-features = [ + "alloc", + "real_blackbox", +] + [dependencies.arbitrary] version = "1" optional = true @@ -56,6 +90,7 @@ default-features = false [dependencies.tinyvec_macros] version = "0.1" optional = true + [dev-dependencies.criterion] version = "0.3.0" @@ -74,4 +109,5 @@ nightly_slice_partition_dedup = [] real_blackbox = ["criterion/real_blackbox"] rustc_1_40 = [] rustc_1_55 = ["rustc_1_40"] -std = [] +rustc_1_57 = ["rustc_1_55"] +std = ["alloc"] diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 28a5874..b18ea9e 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,7 +1,7 @@ [package] name = "tinyvec" description = "`tinyvec` provides 100% safe vec-like data structures." -version = "1.5.1" +version = "1.6.0" authors = ["Lokathor <zefria@gmail.com>"] edition = "2018" license = "Zlib OR Apache-2.0 OR MIT" @@ -23,7 +23,7 @@ default = [] alloc = ["tinyvec_macros"] # Provide things that require Rust's `std` module -std = [] +std = ["alloc"] # (not part of Vec!) Extra methods to let you grab the slice of memory after the # "active" portion of an `ArrayVec` or `SliceVec`. @@ -38,6 +38,10 @@ rustc_1_40 = [] # use const generics to implement Array for all array lengths rustc_1_55 = ["rustc_1_40"] +# features that require rustc 1.57 +# add try_reserve functions to types that heap allocate. +rustc_1_57 = ["rustc_1_55"] + # allow use of nightly feature `slice_partition_dedup`, # will become useless once that is stabilized: # https://github.com/rust-lang/rust/issues/54279 @@ -1,3 +1,7 @@ +# This project was upgraded with external_updater. +# Usage: tools/external_updater/updater.sh update rust/crates/tinyvec +# For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md + name: "tinyvec" description: "`tinyvec` provides 100% safe vec-like data structures." third_party { @@ -7,13 +11,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/tinyvec/tinyvec-1.5.1.crate" + value: "https://static.crates.io/crates/tinyvec/tinyvec-1.6.0.crate" } - version: "1.5.1" + version: "1.6.0" license_type: NOTICE last_upgrade_date { year: 2022 - month: 3 - day: 1 + month: 12 + day: 19 } } diff --git a/TEST_MAPPING b/TEST_MAPPING index 88d573d..0b0519b 100644 --- a/TEST_MAPPING +++ b/TEST_MAPPING @@ -9,21 +9,18 @@ }, { "path": "external/rust/crates/url" + }, + { + "path": "packages/modules/DnsResolver" } ], "presubmit": [ { - "name": "doh_unit_test" - }, - { "name": "tinyvec_test_tests_arrayvec" } ], "presubmit-rust": [ { - "name": "doh_unit_test" - }, - { "name": "tinyvec_test_tests_arrayvec" } ] diff --git a/cargo2android.json b/cargo2android.json index 5974d19..811fadf 100644 --- a/cargo2android.json +++ b/cargo2android.json @@ -1,11 +1,12 @@ { + "add-toplevel-block": "cargo2android_nostd.bp", "apex-available": [ "//apex_available:platform", "com.android.resolv" ], "dependencies": true, "device": true, - "features": "alloc,default,tinyvec_macros", + "features": "alloc,default,std,tinyvec_macros", "min-sdk-version": "29", "run": true, "tests": true diff --git a/cargo2android_nostd.bp b/cargo2android_nostd.bp new file mode 100644 index 0000000..d18c622 --- /dev/null +++ b/cargo2android_nostd.bp @@ -0,0 +1,16 @@ +rust_library_rlib { + name: "libtinyvec_nostd", + crate_name: "tinyvec", + cargo_env_compat: true, + cargo_pkg_version: "1.5.1", + srcs: ["src/lib.rs"], + edition: "2018", + prefer_rlib: true, + no_stdlibs: true, + stdlibs: [ + "libcompiler_builtins.rust_sysroot", + "libcore.rust_sysroot", + ], + vendor_available: true, + min_sdk_version: "29", +} diff --git a/patches/std.diff b/patches/std.diff deleted file mode 100644 index 36d5c7d..0000000 --- a/patches/std.diff +++ /dev/null @@ -1,14 +0,0 @@ -diff --git a/src/lib.rs b/src/lib.rs -index c26f0c5..ce06601 100644 ---- a/src/lib.rs -+++ b/src/lib.rs -@@ -66,6 +66,9 @@ - //! the `Array` trait. The actual usage of the crate is not expected to break
- //! significantly in this transition.
-
-+// ANDROID: Unconditionally use std to allow building as a dylib.
-+extern crate std;
-+
- #[allow(unused_imports)]
- use core::{
- borrow::{Borrow, BorrowMut},
diff --git a/src/arrayvec.rs b/src/arrayvec.rs index 7cf1bfc..9cfe58d 100644 --- a/src/arrayvec.rs +++ b/src/arrayvec.rs @@ -1271,7 +1271,7 @@ impl<A: Array> From<A> for ArrayVec<A> { .as_slice()
.len()
.try_into()
- .expect("ArrayVec::from> lenght must be in range 0..=u16::MAX");
+ .expect("ArrayVec::from> length must be in range 0..=u16::MAX");
Self { len, data }
}
}
@@ -1281,6 +1281,15 @@ impl<A: Array> From<A> for ArrayVec<A> { #[derive(Debug, Copy, Clone)]
pub struct TryFromSliceError(());
+impl core::fmt::Display for TryFromSliceError {
+ fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
+ f.write_str("could not convert slice to ArrayVec")
+ }
+}
+
+#[cfg(feature = "std")]
+impl std::error::Error for TryFromSliceError {}
+
impl<T, A> TryFrom<&'_ [T]> for ArrayVec<A>
where
T: Clone + Default,
@@ -1744,6 +1753,9 @@ where #[cfg(feature = "alloc")]
use alloc::vec::Vec;
+#[cfg(all(feature = "alloc", feature = "rustc_1_57"))]
+use alloc::collections::TryReserveError;
+
#[cfg(feature = "alloc")]
impl<A: Array> ArrayVec<A> {
/// Drains all elements to a Vec, but reserves additional space
@@ -1763,6 +1775,34 @@ impl<A: Array> ArrayVec<A> { return v;
}
+ /// Tries to drain all elements to a Vec, but reserves additional space.
+ ///
+ /// # Errors
+ ///
+ /// If the allocator reports a failure, then an error is returned.
+ ///
+ /// ```
+ /// # use tinyvec::*;
+ /// let mut av = array_vec!([i32; 7] => 1, 2, 3);
+ /// let v = av.try_drain_to_vec_and_reserve(10);
+ /// assert!(matches!(v, Ok(_)));
+ /// let v = v.unwrap();
+ /// assert_eq!(v, &[1, 2, 3]);
+ /// assert_eq!(v.capacity(), 13);
+ /// ```
+ #[cfg(feature = "rustc_1_57")]
+ pub fn try_drain_to_vec_and_reserve(
+ &mut self, n: usize,
+ ) -> Result<Vec<A::Item>, TryReserveError> {
+ let cap = n + self.len();
+ let mut v = Vec::new();
+ v.try_reserve(cap)?;
+ let iter = self.iter_mut().map(take);
+ v.extend(iter);
+ self.set_len(0);
+ return Ok(v);
+ }
+
/// Drains all elements to a Vec
/// ```
/// # use tinyvec::*;
@@ -1774,6 +1814,27 @@ impl<A: Array> ArrayVec<A> { pub fn drain_to_vec(&mut self) -> Vec<A::Item> {
self.drain_to_vec_and_reserve(0)
}
+
+ /// Tries to drain all elements to a Vec.
+ ///
+ /// # Errors
+ ///
+ /// If the allocator reports a failure, then an error is returned.
+ ///
+ /// ```
+ /// # use tinyvec::*;
+ /// let mut av = array_vec!([i32; 7] => 1, 2, 3);
+ /// let v = av.try_drain_to_vec();
+ /// assert!(matches!(v, Ok(_)));
+ /// let v = v.unwrap();
+ /// assert_eq!(v, &[1, 2, 3]);
+ /// // Vec may reserve more than necessary in order to prevent more future allocations.
+ /// assert!(v.capacity() >= 3);
+ /// ```
+ #[cfg(feature = "rustc_1_57")]
+ pub fn try_drain_to_vec(&mut self) -> Result<Vec<A::Item>, TryReserveError> {
+ self.try_drain_to_vec_and_reserve(0)
+ }
}
#[cfg(feature = "serde")]
@@ -62,9 +62,6 @@ //! the `Array` trait. The actual usage of the crate is not expected to break
//! significantly in this transition.
-// ANDROID: Unconditionally use std to allow building as a dylib.
-extern crate std;
-
#[allow(unused_imports)]
use core::{
borrow::{Borrow, BorrowMut},
diff --git a/src/tinyvec.rs b/src/tinyvec.rs index 1e11a47..a5e1c15 100644 --- a/src/tinyvec.rs +++ b/src/tinyvec.rs @@ -6,6 +6,9 @@ use alloc::vec::{self, Vec}; use core::convert::TryFrom;
use tinyvec_macros::impl_mirrored;
+#[cfg(feature = "rustc_1_57")]
+use alloc::collections::TryReserveError;
+
#[cfg(feature = "serde")]
use core::marker::PhantomData;
#[cfg(feature = "serde")]
@@ -300,6 +303,32 @@ impl<A: Array> TinyVec<A> { *self = TinyVec::Heap(v);
}
+ /// Tries to move the content of the TinyVec to the heap, if it's inline.
+ ///
+ /// # Errors
+ ///
+ /// If the allocator reports a failure, then an error is returned and the
+ /// content is kept on the stack.
+ ///
+ /// ```rust
+ /// use tinyvec::*;
+ /// let mut tv = tiny_vec!([i32; 4] => 1, 2, 3);
+ /// assert!(tv.is_inline());
+ /// assert_eq!(Ok(()), tv.try_move_to_the_heap());
+ /// assert!(tv.is_heap());
+ /// ```
+ #[cfg(feature = "rustc_1_57")]
+ pub fn try_move_to_the_heap(&mut self) -> Result<(), TryReserveError> {
+ let arr = match self {
+ TinyVec::Heap(_) => return Ok(()),
+ TinyVec::Inline(a) => a,
+ };
+
+ let v = arr.try_drain_to_vec()?;
+ *self = TinyVec::Heap(v);
+ return Ok(());
+ }
+
/// If TinyVec is inline, moves the content of it to the heap.
/// Also reserves additional space.
/// ```rust
@@ -320,6 +349,35 @@ impl<A: Array> TinyVec<A> { *self = TinyVec::Heap(v);
}
+ /// If TinyVec is inline, try to move the content of it to the heap.
+ /// Also reserves additional space.
+ ///
+ /// # Errors
+ ///
+ /// If the allocator reports a failure, then an error is returned.
+ ///
+ /// ```rust
+ /// use tinyvec::*;
+ /// let mut tv = tiny_vec!([i32; 4] => 1, 2, 3);
+ /// assert!(tv.is_inline());
+ /// assert_eq!(Ok(()), tv.try_move_to_the_heap_and_reserve(32));
+ /// assert!(tv.is_heap());
+ /// assert!(tv.capacity() >= 35);
+ /// ```
+ #[cfg(feature = "rustc_1_57")]
+ pub fn try_move_to_the_heap_and_reserve(
+ &mut self, n: usize,
+ ) -> Result<(), TryReserveError> {
+ let arr = match self {
+ TinyVec::Heap(h) => return h.try_reserve(n),
+ TinyVec::Inline(a) => a,
+ };
+
+ let v = arr.try_drain_to_vec_and_reserve(n)?;
+ *self = TinyVec::Heap(v);
+ return Ok(());
+ }
+
/// Reserves additional space.
/// Moves to the heap if array can't hold `n` more items
/// ```rust
@@ -345,6 +403,37 @@ impl<A: Array> TinyVec<A> { return;
}
+ /// Tries to reserve additional space.
+ /// Moves to the heap if array can't hold `n` more items.
+ ///
+ /// # Errors
+ ///
+ /// If the allocator reports a failure, then an error is returned.
+ ///
+ /// ```rust
+ /// use tinyvec::*;
+ /// let mut tv = tiny_vec!([i32; 4] => 1, 2, 3, 4);
+ /// assert!(tv.is_inline());
+ /// assert_eq!(Ok(()), tv.try_reserve(1));
+ /// assert!(tv.is_heap());
+ /// assert!(tv.capacity() >= 5);
+ /// ```
+ #[cfg(feature = "rustc_1_57")]
+ pub fn try_reserve(&mut self, n: usize) -> Result<(), TryReserveError> {
+ let arr = match self {
+ TinyVec::Heap(h) => return h.try_reserve(n),
+ TinyVec::Inline(a) => a,
+ };
+
+ if n > arr.capacity() - arr.len() {
+ let v = arr.try_drain_to_vec_and_reserve(n)?;
+ *self = TinyVec::Heap(v);
+ }
+
+ /* In this place array has enough place, so no work is needed more */
+ return Ok(());
+ }
+
/// Reserves additional space.
/// Moves to the heap if array can't hold `n` more items
///
@@ -377,6 +466,43 @@ impl<A: Array> TinyVec<A> { return;
}
+ /// Tries to reserve additional space.
+ /// Moves to the heap if array can't hold `n` more items
+ ///
+ /// # Errors
+ ///
+ /// If the allocator reports a failure, then an error is returned.
+ ///
+ /// From [Vec::try_reserve_exact](https://doc.rust-lang.org/std/vec/struct.Vec.html#method.try_reserve_exact)
+ /// ```text
+ /// Note that the allocator may give the collection more space than it requests.
+ /// Therefore, capacity can not be relied upon to be precisely minimal.
+ /// Prefer `reserve` if future insertions are expected.
+ /// ```
+ /// ```rust
+ /// use tinyvec::*;
+ /// let mut tv = tiny_vec!([i32; 4] => 1, 2, 3, 4);
+ /// assert!(tv.is_inline());
+ /// assert_eq!(Ok(()), tv.try_reserve_exact(1));
+ /// assert!(tv.is_heap());
+ /// assert!(tv.capacity() >= 5);
+ /// ```
+ #[cfg(feature = "rustc_1_57")]
+ pub fn try_reserve_exact(&mut self, n: usize) -> Result<(), TryReserveError> {
+ let arr = match self {
+ TinyVec::Heap(h) => return h.try_reserve_exact(n),
+ TinyVec::Inline(a) => a,
+ };
+
+ if n > arr.capacity() - arr.len() {
+ let v = arr.try_drain_to_vec_and_reserve(n)?;
+ *self = TinyVec::Heap(v);
+ }
+
+ /* In this place array has enough place, so no work is needed more */
+ return Ok(());
+ }
+
/// Makes a new TinyVec with _at least_ the given capacity.
///
/// If the requested capacity is less than or equal to the array capacity you
diff --git a/tests/tinyvec.rs b/tests/tinyvec.rs index ab4d9bd..658462a 100644 --- a/tests/tinyvec.rs +++ b/tests/tinyvec.rs @@ -304,6 +304,22 @@ fn TinyVec_reserve() { assert!(tv.capacity() >= 10);
}
+#[cfg(feature = "rustc_1_57")]
+#[test]
+fn TinyVec_try_reserve() {
+ let mut tv: TinyVec<[i32; 4]> = Default::default();
+ assert_eq!(tv.capacity(), 4);
+ tv.extend_from_slice(&[1, 2]);
+ assert_eq!(tv.capacity(), 4);
+ assert!(tv.try_reserve(2).is_ok());
+ assert_eq!(tv.capacity(), 4);
+ assert!(tv.try_reserve(4).is_ok());
+ assert!(tv.capacity() >= 6);
+ tv.extend_from_slice(&[3, 4, 5, 6]);
+ assert!(tv.try_reserve(4).is_ok());
+ assert!(tv.capacity() >= 10);
+}
+
#[test]
fn TinyVec_reserve_exact() {
let mut tv: TinyVec<[i32; 4]> = Default::default();
@@ -320,6 +336,23 @@ fn TinyVec_reserve_exact() { assert!(tv.capacity() >= 10);
}
+#[cfg(feature = "rustc_1_57")]
+#[test]
+fn TinyVec_try_reserve_exact() {
+ let mut tv: TinyVec<[i32; 4]> = Default::default();
+ assert_eq!(tv.capacity(), 4);
+
+ tv.extend_from_slice(&[1, 2]);
+ assert_eq!(tv.capacity(), 4);
+ assert!(tv.try_reserve_exact(2).is_ok());
+ assert_eq!(tv.capacity(), 4);
+ assert!(tv.try_reserve_exact(4).is_ok());
+ assert!(tv.capacity() >= 6);
+ tv.extend_from_slice(&[3, 4, 5, 6]);
+ assert!(tv.try_reserve_exact(4).is_ok());
+ assert!(tv.capacity() >= 10);
+}
+
#[test]
fn TinyVec_move_to_heap_and_shrink() {
let mut tv: TinyVec<[i32; 4]> = Default::default();
@@ -341,6 +374,30 @@ fn TinyVec_move_to_heap_and_shrink() { assert_eq!(tv.as_slice(), [1, 2, 3, 4]);
}
+#[cfg(feature = "rustc_1_57")]
+#[test]
+fn TinyVec_try_move_to_heap_and_shrink() {
+ let mut tv: TinyVec<[i32; 4]> = Default::default();
+ assert!(tv.is_inline());
+ assert!(tv.try_move_to_the_heap().is_ok());
+ assert!(tv.is_heap());
+ assert_eq!(tv.capacity(), 0);
+
+ assert!(tv.try_reserve_exact(1).is_ok());
+ assert_eq!(tv.capacity(), 1);
+ tv.push(1);
+ tv.shrink_to_fit();
+ assert!(tv.is_inline());
+ assert_eq!(tv.capacity(), 4);
+
+ assert!(tv.try_move_to_the_heap_and_reserve(3).is_ok());
+ assert!(tv.is_heap());
+ assert_eq!(tv.capacity(), 4);
+ tv.extend(2..=4);
+ assert_eq!(tv.capacity(), 4);
+ assert_eq!(tv.as_slice(), [1, 2, 3, 4]);
+}
+
#[cfg(feature = "serde")]
#[test]
fn TinyVec_ser_de_empty() {
|