diff --git a/src/slice.rs b/src/slice.rs index 9f307772a..1e57cae1f 100644 --- a/src/slice.rs +++ b/src/slice.rs @@ -35,7 +35,15 @@ pub struct Slice { } impl Slice { + /// Create a new `Slice` with the given extents. + /// + /// See also the `From` impls, converting from ranges; for example + /// `Slice::from(i..)` or `Slice::from(j..k)`. + /// + /// `step` must be nonzero. + /// (This method checks with a debug assertion that `step` is not zero.) pub fn new(start: isize, end: Option, step: isize) -> Slice { + debug_assert_ne!(step, 0, "Slice::new: step must be nonzero"); Slice { start, end, @@ -43,10 +51,15 @@ impl Slice { } } - /// Returns a new `Slice` with the given step size. + /// Create a new `Slice` with the given step size (multiplied with the + /// previous step size). + /// + /// `step` must be nonzero. + /// (This method checks with a debug assertion that `step` is not zero.) #[inline] pub fn step_by(self, step: isize) -> Self { - Slice { step, ..self } + debug_assert_ne!(step, 0, "Slice::step_by: step must be nonzero"); + Slice { step: self.step * step, ..self } } }