(I wanted this today because I need to add some experimental code to an existing production process which cannot afford to fail. I want to reduce the chance of panicing in the new experimental code as much as possible.)
Should it return an Option<&[T]>? A slice with the available elements? Or a Result<&[T], &[T]> (where the error part is the available elements on overflow)?
In my limited experience these things are usually an error, e.g. some index arithmetic which can blow up in a way you hadn’t thought of, maybe because of a subsequent change.
In this case I’d probably want a Result<&[T], SliceError> so that I can take advantage of try!()
I tried doing so with the Index trait, but it requires returning &Self::Output, so it cannot return a Result, but a &Result, which won’t work here. So, I implemented an example without the trait, requiring a method call instead, like arr.slice(0..5).