Skip to content

Commit

Permalink
API docs/examples for std::slice
Browse files Browse the repository at this point in the history
 - 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.
  • Loading branch information
jasonthompson committed Aug 11, 2014
1 parent ade92c6 commit 371e8cf
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/libcollections/slice.rs
Expand Up @@ -314,6 +314,28 @@ pub trait ImmutableCloneableVector<T> {

/// Create an iterator that yields every possible permutation of the
/// vector in succession.
///
/// # Example
///
/// ```rust
/// let v = [1i, 2, 3];
/// let mut perms = v.permutations();
///
/// for p in perms {
/// println!("{}", p);
/// }
/// ```
///
/// # Example 2: iterating through permutations one by one.
///
/// ```rust
/// let v = [1i, 2, 3];
/// let mut perms = v.permutations();
///
/// assert_eq!(Some(vec![1i, 2, 3]), perms.next());
/// assert_eq!(Some(vec![1i, 3, 2]), perms.next());
/// assert_eq!(Some(vec![3i, 1, 2]), perms.next());
/// ```
fn permutations(self) -> Permutations<T>;
}

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

/// Returns an iterator over all permutations of a vector.
fn permutations(self) -> Permutations<T> {
Permutations{
swaps: ElementSwaps::new(self.len()),
Expand Down Expand Up @@ -580,6 +603,16 @@ pub trait MutableVectorAllocating<'a, T> {
* * src - A mutable vector of `T`
* * start - The index into `src` to start copying from
* * end - The index into `src` to stop copying from
*
* # Example
*
* ```rust
* let mut a = [1i, 2, 3, 4, 5];
* let b = vec![6i, 7, 8];
* let num_moved = a.move_from(b, 0, 3);
* assert_eq!(num_moved, 3);
* assert!(a == [6i, 7, 8, 4, 5]);
* ```
*/
fn move_from(self, src: Vec<T>, start: uint, end: uint) -> uint;
}
Expand Down

5 comments on commit 371e8cf

@bors
Copy link
Contributor

@bors bors commented on 371e8cf Aug 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at jasonthompson@371e8cf

@bors
Copy link
Contributor

@bors bors commented on 371e8cf Aug 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging jasonthompson/rust/docs/slice3 = 371e8cf into auto

@bors
Copy link
Contributor

@bors bors commented on 371e8cf Aug 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jasonthompson/rust/docs/slice3 = 371e8cf merged ok, testing candidate = 9dcf895

@bors
Copy link
Contributor

@bors bors commented on 371e8cf Aug 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 9dcf895

Please sign in to comment.