Feedback on arrayref change

Hi all,

I've just added a new (experimental and to be deleted if I don't get feedback!) feature to my arrayref crate, which provides four macros to enable working with references to arrays rather than just slices, with greater efficiency than slices should provide, and more compile-time checking.

The new feature (see code below) is to enable the array_refs! and array_mut_refs macros to be used with slices (I haven't updated the docs yet), with one of the bits being an expandable slice output, so you can get zero or more array references from the beginning, a slice from the middle, and zero or more array references at the end of a slice. I'm not really pleased with the syntax, which uses ; .. ; to indicate where the middle slice goes. So

let (a,b) = array_refs!(in_slice, 10; ..;);

would make a be a reference to the first 10 elements as an array, and b would be a reference to the rest as a slice.

The aspects I'd like feedback on are:

  1. Is there a nicer syntax I can use? I don't much like the ;..; delimiter, and could replace it by ; alone, but that seems sort of unclear. I'm somewhat stymied by the inability of macros to handle ambiguity. I could just make this another macro, but that seems to be adding complexity where I'd rather not have it.

  2. Can someone with greater experience than I in unsafe code check the safety of these two macros?


1 Like