Skip to content

Commit 30aa5d4

Browse files
authored
Add latest_stable_rust feature (#203)
* add the feature * missing_inline * const version of try_from_array_len, and some missing inlines
1 parent 31c6f67 commit 30aa5d4

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

.github/workflows/rust.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: Test non nightly
3535
if: matrix.rust != '1.47.0' && matrix.rust != 'nightly'
3636
run: |
37-
cargo test --features=alloc,std,grab_spare_slice
37+
cargo test --features=alloc,std,grab_spare_slice,latest_stable_rust
3838
- name: Test on Nightly with All Features
3939
if: matrix.rust == 'nightly'
4040
run: |

Cargo.toml

+8-3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ rustc_1_57 = ["rustc_1_55"]
4747
# add retain_mut function to TinyVec
4848
rustc_1_61 = ["rustc_1_57"]
4949

50+
# We're done with per-version featuring, this feature opts in to all the
51+
# abilities of the latest release of Stable rust, and we don't need a million
52+
# features forever now.
53+
latest_stable_rust = ["rustc_1_61"]
54+
5055
# allow use of nightly feature `slice_partition_dedup`,
5156
# will become useless once that is stabilized:
5257
# https://github.com/rust-lang/rust/issues/54279
@@ -69,11 +74,11 @@ experimental_write_impl = []
6974
real_blackbox = ["criterion/real_blackbox"]
7075

7176
[package.metadata.docs.rs]
72-
features = ["alloc", "std", "grab_spare_slice", "rustc_1_55", "serde"]
73-
rustdoc-args = ["--cfg","docs_rs"]
77+
features = ["alloc", "std", "grab_spare_slice", "latest_stable_rust", "serde"]
78+
rustdoc-args = ["--cfg", "docs_rs"]
7479

7580
[package.metadata.playground]
76-
features = ["alloc", "std", "grab_spare_slice", "rustc_1_55", "serde"]
81+
features = ["alloc", "std", "grab_spare_slice", "latest_stable_rust", "serde"]
7782

7883
[profile.bench]
7984
debug = 2

src/arrayvec.rs

+23
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,7 @@ impl<A: Array> ArrayVec<A> {
10711071
/// If the given length is greater than the capacity of the array this will
10721072
/// error, and you'll get the array back in the `Err`.
10731073
#[inline]
1074+
#[cfg(not(feature = "latest_stable_rust"))]
10741075
pub fn try_from_array_len(data: A, len: usize) -> Result<Self, A> {
10751076
/* Note(Soveu): Should we allow A::CAPACITY > u16::MAX for now? */
10761077
if len <= A::CAPACITY {
@@ -1079,6 +1080,26 @@ impl<A: Array> ArrayVec<A> {
10791080
Err(data)
10801081
}
10811082
}
1083+
1084+
/// Wraps an array, using the given length as the starting length.
1085+
///
1086+
/// If you want to use the whole length of the array, you can just use the
1087+
/// `From` impl.
1088+
///
1089+
/// ## Failure
1090+
///
1091+
/// If the given length is greater than the capacity of the array this will
1092+
/// error, and you'll get the array back in the `Err`.
1093+
#[inline]
1094+
#[cfg(feature = "latest_stable_rust")]
1095+
pub const fn try_from_array_len(data: A, len: usize) -> Result<Self, A> {
1096+
/* Note(Soveu): Should we allow A::CAPACITY > u16::MAX for now? */
1097+
if len <= A::CAPACITY {
1098+
Ok(Self { data, len: len as u16 })
1099+
} else {
1100+
Err(data)
1101+
}
1102+
}
10821103
}
10831104

10841105
impl<A> ArrayVec<A> {
@@ -1883,6 +1904,7 @@ impl<A: Array> ArrayVec<A> {
18831904
/// assert_eq!(v, &[1, 2, 3]);
18841905
/// assert_eq!(v.capacity(), 13);
18851906
/// ```
1907+
#[inline]
18861908
#[cfg(feature = "rustc_1_57")]
18871909
pub fn try_drain_to_vec_and_reserve(
18881910
&mut self, n: usize,
@@ -1925,6 +1947,7 @@ impl<A: Array> ArrayVec<A> {
19251947
/// // Vec may reserve more than necessary in order to prevent more future allocations.
19261948
/// assert!(v.capacity() >= 3);
19271949
/// ```
1950+
#[inline]
19281951
#[cfg(feature = "rustc_1_57")]
19291952
pub fn try_drain_to_vec(&mut self) -> Result<Vec<A::Item>, TryReserveError> {
19301953
self.try_drain_to_vec_and_reserve(0)

src/tinyvec.rs

+4
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ impl<A: Array> TinyVec<A> {
316316
/// assert_eq!(Ok(()), tv.try_move_to_the_heap());
317317
/// assert!(tv.is_heap());
318318
/// ```
319+
#[inline]
319320
#[cfg(feature = "rustc_1_57")]
320321
pub fn try_move_to_the_heap(&mut self) -> Result<(), TryReserveError> {
321322
let arr = match self {
@@ -364,6 +365,7 @@ impl<A: Array> TinyVec<A> {
364365
/// assert!(tv.is_heap());
365366
/// assert!(tv.capacity() >= 35);
366367
/// ```
368+
#[inline]
367369
#[cfg(feature = "rustc_1_57")]
368370
pub fn try_move_to_the_heap_and_reserve(
369371
&mut self, n: usize,
@@ -419,6 +421,7 @@ impl<A: Array> TinyVec<A> {
419421
/// assert!(tv.is_heap());
420422
/// assert!(tv.capacity() >= 5);
421423
/// ```
424+
#[inline]
422425
#[cfg(feature = "rustc_1_57")]
423426
pub fn try_reserve(&mut self, n: usize) -> Result<(), TryReserveError> {
424427
let arr = match self {
@@ -489,6 +492,7 @@ impl<A: Array> TinyVec<A> {
489492
/// assert!(tv.is_heap());
490493
/// assert!(tv.capacity() >= 5);
491494
/// ```
495+
#[inline]
492496
#[cfg(feature = "rustc_1_57")]
493497
pub fn try_reserve_exact(&mut self, n: usize) -> Result<(), TryReserveError> {
494498
let arr = match self {

0 commit comments

Comments
 (0)