Running this playground, it looks like you can't peek_nth with an argument of usize::MAX without panicking.
In a way, this makes sense cause peek_nth gets you an item with index in 0..usize::MAX, so getting the index usize::MAX itself is out of bounds. However, if you peek_nth past the end, this implementation returns None. I assume the implicit contract is that it should always return an option, and not panic.
It's pretty straighforward to special case usize::MAX and just return None if its provided as an argument to peek_nth. Otherwise, it can be kept as panicking and noted in the docs as an example.
Running this playground, it looks like you can't
peek_nthwith an argument ofusize::MAXwithout panicking.In a way, this makes sense cause
peek_nthgets you an item with index in0..usize::MAX, so getting the indexusize::MAXitself is out of bounds. However, if youpeek_nthpast the end, this implementation returns None. I assume the implicit contract is that it should always return an option, and not panic.It's pretty straighforward to special case
usize::MAXand just return None if its provided as an argument topeek_nth. Otherwise, it can be kept as panicking and noted in the docs as an example.