Skip to content

Commit 35d71c6

Browse files
authored
Merge pull request #29 from nxsaken/const
Make `array_ref` and `array_refs` usable in const fn
2 parents fe1355e + c2e1af8 commit 35d71c6

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ macro_rules! array_ref {
5858
($arr:expr, $offset:expr, $len:expr) => {{
5959
{
6060
#[inline]
61-
unsafe fn as_array<T>(slice: &[T]) -> &[T; $len] {
61+
const unsafe fn as_array<T>(slice: &[T]) -> &[T; $len] {
6262
&*(slice.as_ptr() as *const [_; $len])
6363
}
6464
let offset = $offset;
@@ -109,7 +109,7 @@ macro_rules! array_refs {
109109
#[inline]
110110
#[allow(unused_assignments)]
111111
#[allow(clippy::eval_order_dependence)]
112-
unsafe fn as_arrays<T>(a: &[T]) -> ( $( &[T; $pre], )* &[T], $( &[T; $post], )*) {
112+
const unsafe fn as_arrays<T>(a: &[T]) -> ( $( &[T; $pre], )* &[T], $( &[T; $post], )*) {
113113
const MIN_LEN: usize = 0usize $( .saturating_add($pre) )* $( .saturating_add($post) )*;
114114
assert!(MIN_LEN < usize::MAX, "Your arrays are too big, are you trying to hack yourself?!");
115115
let var_len = a.len() - MIN_LEN;
@@ -141,7 +141,7 @@ macro_rules! array_refs {
141141
#[inline]
142142
#[allow(unused_assignments)]
143143
#[allow(clippy::eval_order_dependence)]
144-
unsafe fn as_arrays<T>(a: &[T; $( $len + )* 0 ]) -> ( $( &[T; $len], )* ) {
144+
const unsafe fn as_arrays<T>(a: &[T; $( $len + )* 0 ]) -> ( $( &[T; $len], )* ) {
145145
let mut p = a.as_ptr();
146146
( $( {
147147
let aref = &*(p as *const [T; $len]);

0 commit comments

Comments
 (0)