Skip to content

Commit

Permalink
Merge branch 'master' into more-slice-types
Browse files Browse the repository at this point in the history
  • Loading branch information
bluss authored Nov 28, 2017
2 parents 14ff223 + 9ac07d7 commit ff7498a
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,31 @@ 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,
step,
}
}

/// 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 }
}
}

Expand Down

0 comments on commit ff7498a

Please sign in to comment.