mirror of
https://github.com/openharmony/third_party_rust_tinyvec.git
synced 2026-07-19 14:23:33 -04:00
add nightly_const_generics flag
This commit is contained in:
@@ -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" }
|
||||
|
||||
@@ -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,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)]
|
||||
|
||||
Reference in New Issue
Block a user