Skip to content

Commit 9dcf895

Browse files
committed
auto merge of #16417 : jasonthompson/rust/docs/slice3, r=alexcrichton
- Moved examples for permutations and next into trait definition as comments on pull request #16244. - Fixed (hopefully) issue with erronious commit of changes to src/llvm.
2 parents 9e191cd + 371e8cf commit 9dcf895

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/libcollections/slice.rs

+33
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,28 @@ pub trait ImmutableCloneableVector<T> {
301301

302302
/// Create an iterator that yields every possible permutation of the
303303
/// vector in succession.
304+
///
305+
/// # Example
306+
///
307+
/// ```rust
308+
/// let v = [1i, 2, 3];
309+
/// let mut perms = v.permutations();
310+
///
311+
/// for p in perms {
312+
/// println!("{}", p);
313+
/// }
314+
/// ```
315+
///
316+
/// # Example 2: iterating through permutations one by one.
317+
///
318+
/// ```rust
319+
/// let v = [1i, 2, 3];
320+
/// let mut perms = v.permutations();
321+
///
322+
/// assert_eq!(Some(vec![1i, 2, 3]), perms.next());
323+
/// assert_eq!(Some(vec![1i, 3, 2]), perms.next());
324+
/// assert_eq!(Some(vec![3i, 1, 2]), perms.next());
325+
/// ```
304326
fn permutations(self) -> Permutations<T>;
305327
}
306328

@@ -321,6 +343,7 @@ impl<'a,T:Clone> ImmutableCloneableVector<T> for &'a [T] {
321343
(lefts, rights)
322344
}
323345

346+
/// Returns an iterator over all permutations of a vector.
324347
fn permutations(self) -> Permutations<T> {
325348
Permutations{
326349
swaps: ElementSwaps::new(self.len()),
@@ -567,6 +590,16 @@ pub trait MutableVectorAllocating<'a, T> {
567590
* * src - A mutable vector of `T`
568591
* * start - The index into `src` to start copying from
569592
* * end - The index into `src` to stop copying from
593+
*
594+
* # Example
595+
*
596+
* ```rust
597+
* let mut a = [1i, 2, 3, 4, 5];
598+
* let b = vec![6i, 7, 8];
599+
* let num_moved = a.move_from(b, 0, 3);
600+
* assert_eq!(num_moved, 3);
601+
* assert!(a == [6i, 7, 8, 4, 5]);
602+
* ```
570603
*/
571604
fn move_from(self, src: Vec<T>, start: uint, end: uint) -> uint;
572605
}

0 commit comments

Comments
 (0)