add nightly_const_generics flag

This commit is contained in:
James McGlashan
2020-01-18 00:00:00 +00:00
parent 9a726afafa
commit c49be7b254
3 changed files with 23 additions and 0 deletions
+3
View File
@@ -23,6 +23,9 @@ alloc = []
# https://github.com/rust-lang/rust/issues/54279
nightly_slice_partition_dedup = []
# use const generics for arrays
nightly_const_generics = []
[badges]
appveyor = { repository = "Lokathor/tinyvec" }
travis-ci = { repository = "Lokathor/tinyvec" }
+16
View File
@@ -34,6 +34,21 @@ pub trait Array {
fn as_slice_mut(&mut self) -> &mut [Self::Item];
}
#[cfg(feature = "nightly_const_generics")]
impl<T: Default, const N: usize> Array for [T; N] {
type Item = T;
const CAPACITY: usize = N;
#[inline(always)]
fn as_slice(&self) -> &[T] {
&*self
}
#[inline(always)]
fn as_slice_mut(&mut self) -> &mut [T] {
&mut *self
}
}
#[cfg(not(feature = "nightly_const_generics"))]
macro_rules! impl_array_for_len {
($($len:expr),+ $(,)?) => {
$(impl<T: Default> Array for [T; $len] {
@@ -51,6 +66,7 @@ macro_rules! impl_array_for_len {
}
}
#[cfg(not(feature = "nightly_const_generics"))]
impl_array_for_len! {
0, /* The oft-forgotten 0-length array! */
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+4
View File
@@ -4,6 +4,10 @@
feature = "nightly_slice_partition_dedup",
feature(slice_partition_dedup)
)]
#![cfg_attr(
feature = "nightly_const_generics",
feature(const_generics)
)]
#![warn(clippy::missing_inline_in_public_items)]
#![warn(clippy::must_use_candidate)]
#![warn(missing_docs)]