Skip to content

Fix TODO items #166

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
11 changes: 8 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ tinyvec_macros = { version = "0.1", optional = true }
serde = { version = "1.0", optional = true, default-features = false }
# Provides derived `Arbitrary` implementations
arbitrary = { version = "1", optional = true }
# Detects the available `rustc` version
rustversion = "1.0.7"

[features]
default = []
Expand All @@ -29,17 +31,20 @@ std = ["alloc"]
# "active" portion of an `ArrayVec` or `SliceVec`.
grab_spare_slice = []

# features that require rustc 1.40
# formerly enabled features that require rustc 1.40
# use Vec::append if possible in TinyVec::append - 1.37
# DoubleEndedIterator::nth_back - 1.40
# now these are automatically enabled if the listed rustc versions are detected
rustc_1_40 = []

# features that require rustc 1.55
# formerly enabled features that require rustc 1.55
# use const generics to implement Array for all array lengths
# now that is automatically enabled if rustc 1.55+ is detected
rustc_1_55 = ["rustc_1_40"]

# features that require rustc 1.57
# formerly enabled features that require rustc 1.57
# add try_reserve functions to types that heap allocate.
# now that is automatically enabled if rustc 1.57+ is detected
rustc_1_57 = ["rustc_1_55"]

# allow use of nightly feature `slice_partition_dedup`,
Expand Down
2 changes: 2 additions & 0 deletions gen-array-impls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
gen_impl() {
local len=$1
cat <<-END
#[rustversion::before(1.55)]
impl<T: Default> Array for [T; $len] {
type Item = T;
const CAPACITY: usize = $len;
Expand Down Expand Up @@ -43,6 +44,7 @@ cat <<-END
// ./gen-array-impls.sh > src/array/generated_impl.rs
// from the repo root

#[rustversion::before(1.55)]
use super::Array;

$(for ((i = 0; i <= 33; i++)); do gen_impl $i; done)
Expand Down
3 changes: 2 additions & 1 deletion src-backup/arrayset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ use core::{
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct InsertError;

// TODO(when std): impl std::error::Error for InsertError {}
#[cfg(feature = "std")]
impl std::error::Error for InsertError {}

impl fmt::Display for InsertError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
15 changes: 10 additions & 5 deletions src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
///
/// You are generally **not** expected to need to implement this yourself. It is
/// already implemented for all the major array lengths (`0..=32` and the powers
/// of 2 up to 4,096), or for all array lengths with the feature `rustc_1_55`.
/// of 2 up to 4,096), or for all array lengths in Rust versions 1.55 and newer.
///
/// **Additional lengths can easily be added upon request.**
/// **Additional lengths can easily be added upon request for Rust 1.54 and
/// older.**
///
/// ## Safety Reminder
///
Expand Down Expand Up @@ -41,8 +42,12 @@ pub trait Array {
fn default() -> Self;
}

#[cfg(feature = "rustc_1_55")]
// These `*_impl` modules implement `Array` for primitive arrays.
//
// NOTE(2022-07-09): The `#[rustversion::...]` conditional compilation
// attributes are placed on the individual implementation blocks rather than on
// the modules because using procedural attribute macros on non-inline modules
// is unstable. Even if doing so becomes stable, it would be incompatible with
// `tinyvec`'s MSRV.
mod const_generic_impl;

#[cfg(not(feature = "rustc_1_55"))]
mod generated_impl;
2 changes: 2 additions & 0 deletions src/array/const_generic_impl.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#[rustversion::since(1.55)]
use super::Array;

#[rustversion::since(1.55)]
impl<T: Default, const N: usize> Array for [T; N] {
type Item = T;
const CAPACITY: usize = N;
Expand Down
Loading