Skip to content

Commit 4fafd37

Browse files
committed
Add opt-in const generics support
1 parent 7a8d9e5 commit 4fafd37

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ portaudio = "0.7"
1717
[features]
1818
default = ["std"]
1919
std = []
20+
const_generics = []

src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#![cfg_attr(not(feature = "std"), no_std)]
1414
#![cfg_attr(not(feature = "std"), feature(alloc, core_intrinsics))]
1515

16+
#![cfg_attr(feature = "const_generics", feature(const_generics))]
17+
1618
#[cfg(feature = "std")]
1719
extern crate core;
1820

src/ring_buffer.rs

+22
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,27 @@ impl<T> SliceMut for Vec<T> {
9292
}
9393
}
9494

95+
#[cfg(feature = "const_generics")]
96+
impl<T, const N: usize> Slice for [T; N] {
97+
type Element = T;
98+
#[inline]
99+
fn slice(&self) -> &[Self::Element] {
100+
&self[..]
101+
}
102+
}
103+
#[cfg(feature = "const_generics")]
104+
impl<T, const N: usize> SliceMut for [T; N] {
105+
#[inline]
106+
fn slice_mut(&mut self) -> &mut [Self::Element] {
107+
&mut self[..]
108+
}
109+
}
110+
#[cfg(feature = "const_generics")]
111+
impl<T, const N: usize> FixedSizeArray for [T; N] {
112+
const LEN: usize = N;
113+
}
114+
115+
#[cfg(not(feature = "const_generics"))]
95116
macro_rules! impl_slice_for_arrays {
96117
($($N:expr)*) => {
97118
$(
@@ -115,6 +136,7 @@ macro_rules! impl_slice_for_arrays {
115136
};
116137
}
117138

139+
#[cfg(not(feature = "const_generics"))]
118140
impl_slice_for_arrays! {
119141
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
120142
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

0 commit comments

Comments
 (0)