Skip to content

Commit

Permalink
Make array_ref and array_refs usable in const fn
Browse files Browse the repository at this point in the history
  • Loading branch information
nxsaken committed Sep 13, 2024
1 parent fe1355e commit c2e1af8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ macro_rules! array_ref {
($arr:expr, $offset:expr, $len:expr) => {{
{
#[inline]
unsafe fn as_array<T>(slice: &[T]) -> &[T; $len] {
const unsafe fn as_array<T>(slice: &[T]) -> &[T; $len] {
&*(slice.as_ptr() as *const [_; $len])
}
let offset = $offset;
Expand Down Expand Up @@ -109,7 +109,7 @@ macro_rules! array_refs {
#[inline]
#[allow(unused_assignments)]
#[allow(clippy::eval_order_dependence)]
unsafe fn as_arrays<T>(a: &[T]) -> ( $( &[T; $pre], )* &[T], $( &[T; $post], )*) {
const unsafe fn as_arrays<T>(a: &[T]) -> ( $( &[T; $pre], )* &[T], $( &[T; $post], )*) {
const MIN_LEN: usize = 0usize $( .saturating_add($pre) )* $( .saturating_add($post) )*;
assert!(MIN_LEN < usize::MAX, "Your arrays are too big, are you trying to hack yourself?!");
let var_len = a.len() - MIN_LEN;
Expand Down Expand Up @@ -141,7 +141,7 @@ macro_rules! array_refs {
#[inline]
#[allow(unused_assignments)]
#[allow(clippy::eval_order_dependence)]
unsafe fn as_arrays<T>(a: &[T; $( $len + )* 0 ]) -> ( $( &[T; $len], )* ) {
const unsafe fn as_arrays<T>(a: &[T; $( $len + )* 0 ]) -> ( $( &[T; $len], )* ) {
let mut p = a.as_ptr();
( $( {
let aref = &*(p as *const [T; $len]);
Expand Down

0 comments on commit c2e1af8

Please sign in to comment.