Skip to content

Commit ff7498a

Browse files
authored
Merge branch 'master' into more-slice-types
2 parents 14ff223 + 9ac07d7 commit ff7498a

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/slice.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,31 @@ pub struct Slice {
3535
}
3636

3737
impl Slice {
38+
/// Create a new `Slice` with the given extents.
39+
///
40+
/// See also the `From` impls, converting from ranges; for example
41+
/// `Slice::from(i..)` or `Slice::from(j..k)`.
42+
///
43+
/// `step` must be nonzero.
44+
/// (This method checks with a debug assertion that `step` is not zero.)
3845
pub fn new(start: isize, end: Option<isize>, step: isize) -> Slice {
46+
debug_assert_ne!(step, 0, "Slice::new: step must be nonzero");
3947
Slice {
4048
start,
4149
end,
4250
step,
4351
}
4452
}
4553

46-
/// Returns a new `Slice` with the given step size.
54+
/// Create a new `Slice` with the given step size (multiplied with the
55+
/// previous step size).
56+
///
57+
/// `step` must be nonzero.
58+
/// (This method checks with a debug assertion that `step` is not zero.)
4759
#[inline]
4860
pub fn step_by(self, step: isize) -> Self {
49-
Slice { step, ..self }
61+
debug_assert_ne!(step, 0, "Slice::step_by: step must be nonzero");
62+
Slice { step: self.step * step, ..self }
5063
}
5164
}
5265

0 commit comments

Comments
 (0)