Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add latest_stable_rust feature #203

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Test non nightly
if: matrix.rust != '1.47.0' && matrix.rust != 'nightly'
run: |
cargo test --features=alloc,std,grab_spare_slice
cargo test --features=alloc,std,grab_spare_slice,latest_stable_rust
- name: Test on Nightly with All Features
if: matrix.rust == 'nightly'
run: |
Expand Down
11 changes: 8 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ rustc_1_57 = ["rustc_1_55"]
# add retain_mut function to TinyVec
rustc_1_61 = ["rustc_1_57"]

# We're done with per-version featuring, this feature opts in to all the
# abilities of the latest release of Stable rust, and we don't need a million
# features forever now.
latest_stable_rust = ["rustc_1_61"]

# allow use of nightly feature `slice_partition_dedup`,
# will become useless once that is stabilized:
# https://github.com/rust-lang/rust/issues/54279
Expand All @@ -67,11 +72,11 @@ experimental_write_impl = []
real_blackbox = ["criterion/real_blackbox"]

[package.metadata.docs.rs]
features = ["alloc", "std", "grab_spare_slice", "rustc_1_55", "serde"]
rustdoc-args = ["--cfg","docs_rs"]
features = ["alloc", "std", "grab_spare_slice", "latest_stable_rust", "serde"]
rustdoc-args = ["--cfg", "docs_rs"]

[package.metadata.playground]
features = ["alloc", "std", "grab_spare_slice", "rustc_1_55", "serde"]
features = ["alloc", "std", "grab_spare_slice", "latest_stable_rust", "serde"]

[profile.bench]
debug = 2
Expand Down
23 changes: 23 additions & 0 deletions src/arrayvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,7 @@ impl<A: Array> ArrayVec<A> {
/// If the given length is greater than the capacity of the array this will
/// error, and you'll get the array back in the `Err`.
#[inline]
#[cfg(not(feature = "latest_stable_rust"))]
pub fn try_from_array_len(data: A, len: usize) -> Result<Self, A> {
/* Note(Soveu): Should we allow A::CAPACITY > u16::MAX for now? */
if len <= A::CAPACITY {
Expand All @@ -1079,6 +1080,26 @@ impl<A: Array> ArrayVec<A> {
Err(data)
}
}

/// Wraps an array, using the given length as the starting length.
///
/// If you want to use the whole length of the array, you can just use the
/// `From` impl.
///
/// ## Failure
///
/// If the given length is greater than the capacity of the array this will
/// error, and you'll get the array back in the `Err`.
#[inline]
#[cfg(feature = "latest_stable_rust")]
pub const fn try_from_array_len(data: A, len: usize) -> Result<Self, A> {
/* Note(Soveu): Should we allow A::CAPACITY > u16::MAX for now? */
if len <= A::CAPACITY {
Ok(Self { data, len: len as u16 })
} else {
Err(data)
}
}
}

impl<A> ArrayVec<A> {
Expand Down Expand Up @@ -1883,6 +1904,7 @@ impl<A: Array> ArrayVec<A> {
/// assert_eq!(v, &[1, 2, 3]);
/// assert_eq!(v.capacity(), 13);
/// ```
#[inline]
#[cfg(feature = "rustc_1_57")]
pub fn try_drain_to_vec_and_reserve(
&mut self, n: usize,
Expand Down Expand Up @@ -1925,6 +1947,7 @@ impl<A: Array> ArrayVec<A> {
/// // Vec may reserve more than necessary in order to prevent more future allocations.
/// assert!(v.capacity() >= 3);
/// ```
#[inline]
#[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)
Expand Down
4 changes: 4 additions & 0 deletions src/tinyvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ impl<A: Array> TinyVec<A> {
/// assert_eq!(Ok(()), tv.try_move_to_the_heap());
/// assert!(tv.is_heap());
/// ```
#[inline]
#[cfg(feature = "rustc_1_57")]
pub fn try_move_to_the_heap(&mut self) -> Result<(), TryReserveError> {
let arr = match self {
Expand Down Expand Up @@ -364,6 +365,7 @@ impl<A: Array> TinyVec<A> {
/// assert!(tv.is_heap());
/// assert!(tv.capacity() >= 35);
/// ```
#[inline]
#[cfg(feature = "rustc_1_57")]
pub fn try_move_to_the_heap_and_reserve(
&mut self, n: usize,
Expand Down Expand Up @@ -419,6 +421,7 @@ impl<A: Array> TinyVec<A> {
/// assert!(tv.is_heap());
/// assert!(tv.capacity() >= 5);
/// ```
#[inline]
#[cfg(feature = "rustc_1_57")]
pub fn try_reserve(&mut self, n: usize) -> Result<(), TryReserveError> {
let arr = match self {
Expand Down Expand Up @@ -489,6 +492,7 @@ impl<A: Array> TinyVec<A> {
/// assert!(tv.is_heap());
/// assert!(tv.capacity() >= 5);
/// ```
#[inline]
#[cfg(feature = "rustc_1_57")]
pub fn try_reserve_exact(&mut self, n: usize) -> Result<(), TryReserveError> {
let arr = match self {
Expand Down
Loading