Repository navigation
Add support for slicing with inclusive ranges - #467
Conversation
Rust 1.26 added support for inclusive ranges, which can be created with syntax `start..=end` or `..=end`. This commit bumps the required Rust version to 1.27 because the `.start()` and `.end()` methods of `RangeInclusive` were added only in 1.27.
f90f843 to
4405d36
Compare
|
I just pushed a new version because it turns out that the |
nilgoyette
left a comment
There was a problem hiding this comment.
Some questions about macros, but apart from that, lgtm.
|
|
||
| impl<D1: Dimension, T> SliceNextDim<D1, D1::Larger> for RangeInclusive<T> { | ||
| fn next_dim(&self, _: PhantomData<D1>) -> PhantomData<D1::Larger> { | ||
| PhantomData |
There was a problem hiding this comment.
Another macro question :) From line 499 to 527, would it be possible to create a macro for that? next_dim is implemented for all types of Range except RangeFull.
There was a problem hiding this comment.
Yes, it is a lot more concise with a macro. Thanks!
| step: 1, | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Line 70 to 129 and 265 to 324. do you think it would a good place for a macro? They are already macros, but it could be a merge of impl_slice_from_index_type and impl_sliceorindex_from_index_type. The only change in all those lines is Slice and SliceOrIndex.
It's a real question btw. Maybe too much macro make the code unreadable or un-fun or wathever. Or maybe the special case From<$index> make this more complex?
There was a problem hiding this comment.
I've merged the macros as you've suggested, which substantially reduced the duplication. The special case is not an issue; I've kept a separate macro for it.
Thanks for pointing this out!
|
My usual attention for inclusive ranges would be to overflow issues, and I haven't really looked closely enough at that here |
|
A few notes:
|
Rust 1.26 added support for inclusive ranges, which can be created with syntax
start..=endor..=end.The behavior of this implementation is a little weird in the rare case that
range.end == ::std::isize::MAXdue to overflow, but without changing the representation ofSliceandSliceOrIndex, I don't see a good way to handle that case cleanly. This shouldn't be a significant issue in practice because:range.end == ::std::isize::MAX.slice.end = 0, which will result in a panic when slicing unlessslice.start == 0, which will result in an empty slice. The panic is reasonable behavior. The empty slice behavior in theslice.start == 0case isn't ideal, but I wouldn't expect it to result in any significant problems.