diff options
| author | Michael Sproul <micsproul@gmail.com> | 2014-08-29 10:03:30 +1000 |
|---|---|---|
| committer | Michael Sproul <micsproul@gmail.com> | 2014-08-29 11:09:12 +1000 |
| commit | db7c7c23a49081001bd4ceb652fec86b73d7806b (patch) | |
| tree | 626bc00a3156427f69abbc2f62a1a4c1115d325e | |
| parent | ba39b50943aa55790f79ccdebc446b0f7e6d0d3f (diff) | |
| download | rust-db7c7c23a49081001bd4ceb652fec86b73d7806b.tar.gz rust-db7c7c23a49081001bd4ceb652fec86b73d7806b.zip | |
doc: Clarify slice failure conditions.
| -rw-r--r-- | src/libcore/slice.rs | 61 |
1 files changed, 33 insertions, 28 deletions
diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 5a70cd8c847..774365366cc 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -57,31 +57,31 @@ use raw::Slice as RawSlice; // Extension traits // -/// Extension methods for vectors +/// Extension methods for immutable slices. #[unstable = "may merge with other traits; region parameter may disappear"] pub trait ImmutableSlice<'a, T> { - /** - * Returns a slice of self spanning the interval [`start`, `end`). - * - * Fails when the slice (or part of it) is outside the bounds of self, - * or when `start` > `end`. - */ + /// Returns a subslice spanning the interval [`start`, `end`). + /// + /// Fails when the end of the new slice lies beyond the end of the + /// original slice (i.e. when `end > self.len()`) or when `start > end`. + /// + /// Slicing with `start` equal to `end` yields an empty slice. #[unstable] fn slice(&self, start: uint, end: uint) -> &'a [T]; - /** - * Returns a slice of self from `start` to the end of the vec. - * - * Fails when `start` points outside the bounds of self. - */ + /// Returns a subslice from `start` to the end of the slice. + /// + /// Fails when `start` is strictly greater than the length of the original slice. + /// + /// Slicing from `self.len()` yields an empty slice. #[unstable] fn slice_from(&self, start: uint) -> &'a [T]; - /** - * Returns a slice of self from the start of the vec to `end`. - * - * Fails when `end` points outside the bounds of self. - */ + /// Returns a subslice from the start of the slice to `end`. + /// + /// Fails when `end` is strictly greater than the length of the original slice. + /// + /// Slicing to `0` yields an empty slice. #[unstable] fn slice_to(&self, end: uint) -> &'a [T]; @@ -486,21 +486,26 @@ pub trait MutableSlice<'a, T> { /// Primarily intended for getting a &mut [T] from a [T, ..N]. fn as_mut_slice(self) -> &'a mut [T]; - /// Return a slice that points into another slice. + /// Returns a mutable subslice spanning the interval [`start`, `end`). + /// + /// Fails when the end of the new slice lies beyond the end of the + /// original slice (i.e. when `end > self.len()`) or when `start > end`. + /// + /// Slicing with `start` equal to `end` yields an empty slice. fn mut_slice(self, start: uint, end: uint) -> &'a mut [T]; - /** - * Returns a slice of self from `start` to the end of the vec. - * - * Fails when `start` points outside the bounds of self. - */ + /// Returns a mutable subslice from `start` to the end of the slice. + /// + /// Fails when `start` is strictly greater than the length of the original slice. + /// + /// Slicing from `self.len()` yields an empty slice. fn mut_slice_from(self, start: uint) -> &'a mut [T]; - /** - * Returns a slice of self from the start of the vec to `end`. - * - * Fails when `end` points outside the bounds of self. - */ + /// Returns a mutable subslice from the start of the slice to `end`. + /// + /// Fails when `end` is strictly greater than the length of the original slice. + /// + /// Slicing to `0` yields an empty slice. fn mut_slice_to(self, end: uint) -> &'a mut [T]; /// Returns an iterator that allows modifying each value |
