diff --git a/.travis.yml b/.travis.yml index 3fc6bc00..087660e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,4 +9,8 @@ script: - cargo check -v - cargo test -v - cargo test --release -v +- | + [ "$TRAVIS_RUST_VERSION" != "nightly" ] || cargo test --features const_generics -v +- | + [ "$TRAVIS_RUST_VERSION" != "nightly" ] || cargo test --features const_generics --release -v - cargo doc -v diff --git a/Cargo.toml b/Cargo.toml index f2533471..d9886a40 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,3 +17,4 @@ portaudio = "0.7" [features] default = ["std"] std = [] +const_generics = [] diff --git a/src/lib.rs b/src/lib.rs index 6142892e..f6091613 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,6 +13,8 @@ #![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(not(feature = "std"), feature(alloc, core_intrinsics))] +#![cfg_attr(feature = "const_generics", feature(const_generics))] + #[cfg(feature = "std")] extern crate core; diff --git a/src/ring_buffer.rs b/src/ring_buffer.rs index 9b6b9de4..888df843 100644 --- a/src/ring_buffer.rs +++ b/src/ring_buffer.rs @@ -92,6 +92,27 @@ impl SliceMut for Vec { } } +#[cfg(feature = "const_generics")] +impl Slice for [T; N] { + type Element = T; + #[inline] + fn slice(&self) -> &[Self::Element] { + &self[..] + } +} +#[cfg(feature = "const_generics")] +impl SliceMut for [T; N] { + #[inline] + fn slice_mut(&mut self) -> &mut [Self::Element] { + &mut self[..] + } +} +#[cfg(feature = "const_generics")] +impl FixedSizeArray for [T; N] { + const LEN: usize = N; +} + +#[cfg(not(feature = "const_generics"))] macro_rules! impl_slice_for_arrays { ($($N:expr)*) => { $( @@ -115,6 +136,7 @@ macro_rules! impl_slice_for_arrays { }; } +#[cfg(not(feature = "const_generics"))] impl_slice_for_arrays! { 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65