Skip to content

Commit db7c7c2

Browse files
committed
doc: Clarify slice failure conditions.
1 parent ba39b50 commit db7c7c2

File tree

1 file changed

+33
-28
lines changed

1 file changed

+33
-28
lines changed

src/libcore/slice.rs

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -57,31 +57,31 @@ use raw::Slice as RawSlice;
5757
// Extension traits
5858
//
5959

60-
/// Extension methods for vectors
60+
/// Extension methods for immutable slices.
6161
#[unstable = "may merge with other traits; region parameter may disappear"]
6262
pub trait ImmutableSlice<'a, T> {
63-
/**
64-
* Returns a slice of self spanning the interval [`start`, `end`).
65-
*
66-
* Fails when the slice (or part of it) is outside the bounds of self,
67-
* or when `start` > `end`.
68-
*/
63+
/// Returns a subslice spanning the interval [`start`, `end`).
64+
///
65+
/// Fails when the end of the new slice lies beyond the end of the
66+
/// original slice (i.e. when `end > self.len()`) or when `start > end`.
67+
///
68+
/// Slicing with `start` equal to `end` yields an empty slice.
6969
#[unstable]
7070
fn slice(&self, start: uint, end: uint) -> &'a [T];
7171

72-
/**
73-
* Returns a slice of self from `start` to the end of the vec.
74-
*
75-
* Fails when `start` points outside the bounds of self.
76-
*/
72+
/// Returns a subslice from `start` to the end of the slice.
73+
///
74+
/// Fails when `start` is strictly greater than the length of the original slice.
75+
///
76+
/// Slicing from `self.len()` yields an empty slice.
7777
#[unstable]
7878
fn slice_from(&self, start: uint) -> &'a [T];
7979

80-
/**
81-
* Returns a slice of self from the start of the vec to `end`.
82-
*
83-
* Fails when `end` points outside the bounds of self.
84-
*/
80+
/// Returns a subslice from the start of the slice to `end`.
81+
///
82+
/// Fails when `end` is strictly greater than the length of the original slice.
83+
///
84+
/// Slicing to `0` yields an empty slice.
8585
#[unstable]
8686
fn slice_to(&self, end: uint) -> &'a [T];
8787

@@ -486,21 +486,26 @@ pub trait MutableSlice<'a, T> {
486486
/// Primarily intended for getting a &mut [T] from a [T, ..N].
487487
fn as_mut_slice(self) -> &'a mut [T];
488488

489-
/// Return a slice that points into another slice.
489+
/// Returns a mutable subslice spanning the interval [`start`, `end`).
490+
///
491+
/// Fails when the end of the new slice lies beyond the end of the
492+
/// original slice (i.e. when `end > self.len()`) or when `start > end`.
493+
///
494+
/// Slicing with `start` equal to `end` yields an empty slice.
490495
fn mut_slice(self, start: uint, end: uint) -> &'a mut [T];
491496

492-
/**
493-
* Returns a slice of self from `start` to the end of the vec.
494-
*
495-
* Fails when `start` points outside the bounds of self.
496-
*/
497+
/// Returns a mutable subslice from `start` to the end of the slice.
498+
///
499+
/// Fails when `start` is strictly greater than the length of the original slice.
500+
///
501+
/// Slicing from `self.len()` yields an empty slice.
497502
fn mut_slice_from(self, start: uint) -> &'a mut [T];
498503

499-
/**
500-
* Returns a slice of self from the start of the vec to `end`.
501-
*
502-
* Fails when `end` points outside the bounds of self.
503-
*/
504+
/// Returns a mutable subslice from the start of the slice to `end`.
505+
///
506+
/// Fails when `end` is strictly greater than the length of the original slice.
507+
///
508+
/// Slicing to `0` yields an empty slice.
504509
fn mut_slice_to(self, end: uint) -> &'a mut [T];
505510

506511
/// Returns an iterator that allows modifying each value

0 commit comments

Comments
 (0)