Skip to content

Commit 98c0878

Browse files
committed
API: Add debug assertions for step != 0 in Slice::new, step_by
1 parent 3d9134b commit 98c0878

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/slice.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,15 @@ 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,
@@ -44,8 +52,12 @@ impl Slice {
4452
}
4553

4654
/// Returns a new `Slice` with the given step size.
55+
///
56+
/// `step` must be nonzero.
57+
/// (This method checks with a debug assertion that `step` is not zero.)
4758
#[inline]
48-
pub fn step_by(self, step: Ixs) -> Self {
59+
pub fn step_by(self, step: isize) -> Self {
60+
debug_assert_ne!(step, 0, "Slice::step_by: step must be nonzero");
4961
Slice { step, ..self }
5062
}
5163
}

0 commit comments

Comments
 (0)