Skip to content

Commit 371e8cf

Browse files
committed
API docs/examples for std::slice
- API doc/example for next() in Permutations - API doc/example for permutations() in ImmutableCloneableVector - Moved examples for permutations and next into trait definition as comments on pull request #16244. - Fix erroneus inclusion of src/llvm in older commit.
1 parent ade92c6 commit 371e8cf

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
@@ -314,6 +314,28 @@ pub trait ImmutableCloneableVector<T> {
314314

315315
/// Create an iterator that yields every possible permutation of the
316316
/// vector in succession.
317+
///
318+
/// # Example
319+
///
320+
/// ```rust
321+
/// let v = [1i, 2, 3];
322+
/// let mut perms = v.permutations();
323+
///
324+
/// for p in perms {
325+
/// println!("{}", p);
326+
/// }
327+
/// ```
328+
///
329+
/// # Example 2: iterating through permutations one by one.
330+
///
331+
/// ```rust
332+
/// let v = [1i, 2, 3];
333+
/// let mut perms = v.permutations();
334+
///
335+
/// assert_eq!(Some(vec![1i, 2, 3]), perms.next());
336+
/// assert_eq!(Some(vec![1i, 3, 2]), perms.next());
337+
/// assert_eq!(Some(vec![3i, 1, 2]), perms.next());
338+
/// ```
317339
fn permutations(self) -> Permutations<T>;
318340
}
319341

@@ -334,6 +356,7 @@ impl<'a,T:Clone> ImmutableCloneableVector<T> for &'a [T] {
334356
(lefts, rights)
335357
}
336358

359+
/// Returns an iterator over all permutations of a vector.
337360
fn permutations(self) -> Permutations<T> {
338361
Permutations{
339362
swaps: ElementSwaps::new(self.len()),
@@ -580,6 +603,16 @@ pub trait MutableVectorAllocating<'a, T> {
580603
* * src - A mutable vector of `T`
581604
* * start - The index into `src` to start copying from
582605
* * end - The index into `src` to stop copying from
606+
*
607+
* # Example
608+
*
609+
* ```rust
610+
* let mut a = [1i, 2, 3, 4, 5];
611+
* let b = vec![6i, 7, 8];
612+
* let num_moved = a.move_from(b, 0, 3);
613+
* assert_eq!(num_moved, 3);
614+
* assert!(a == [6i, 7, 8, 4, 5]);
615+
* ```
583616
*/
584617
fn move_from(self, src: Vec<T>, start: uint, end: uint) -> uint;
585618
}

0 commit comments

Comments
 (0)