Skip to content

Commit

Permalink
API: Add debug assertions for step != 0 in Slice::new, step_by
Browse files Browse the repository at this point in the history
  • Loading branch information
bluss committed Nov 28, 2017
1 parent 3d9134b commit 98c0878
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<isize>, step: isize) -> Slice {
debug_assert_ne!(step, 0, "Slice::new: step must be nonzero");
Slice {
start,
end,
Expand All @@ -44,8 +52,12 @@ impl Slice {
}

/// Returns a new `Slice` with the given 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: Ixs) -> Self {
pub fn step_by(self, step: isize) -> Self {
debug_assert_ne!(step, 0, "Slice::step_by: step must be nonzero");
Slice { step, ..self }
}
}
Expand Down

0 comments on commit 98c0878

Please sign in to comment.