Is there a range expression that can be used to refer to the last N elements of a slice?

Viewed 112

I have a slice of unknown length and I would like to try get a slice to the last N elements of that slice. The only way I can think of doing this is as follows (e.g., for 4 elements):

if let [.., a, b, c, d] = my_slice {
    //...
}

This feels very cumbersome though. I would have thought that one of the range expressions would have provided this functionality, but none of them seem to do so... Is there another way of doing this? Ideally, I would be able to work with a slice and not the individual values a, b, c, d in my example above.

1 Answers
Related