From e63af30615c6bab580de050c2308f523196c822d Mon Sep 17 00:00:00 2001 From: Jason Thompson Date: Thu, 31 Jul 2014 06:13:44 -0400 Subject: [PATCH 1/2] API docs/examples for std::slice - API example for move_from in MutableVectorAllocating - API doc/example for next() in Permutations - API doc/example for permutations() in ImmutableCloneableVector --- src/libcollections/slice.rs | 34 ++++++++++++++++++++++++++++++++++ src/llvm | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 5b1722b276916..55678682f2b69 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -256,6 +256,18 @@ pub struct Permutations { } impl Iterator> for Permutations { + /// Returns next permuation in Iterator of all possible + /// permuations of a vector. + /// + /// # Example + /// + /// ```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()); + /// ``` #[inline] fn next(&mut self) -> Option> { match self.swaps.next() { @@ -334,6 +346,18 @@ impl<'a,T:Clone> ImmutableCloneableVector for &'a [T] { (lefts, rights) } + /// Returns an iterator over all permutations of a vector. + /// + /// # Example + /// + /// ```rust + /// let v = [1i, 2, 3]; + /// let mut perms = v.permutations(); + /// + /// for p in perms { + /// println!("{}", p); + /// } + /// ``` fn permutations(self) -> Permutations { Permutations{ swaps: ElementSwaps::new(self.len()), @@ -580,6 +604,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, start: uint, end: uint) -> uint; } diff --git a/src/llvm b/src/llvm index 0d999e5b315b6..1bba09755d958 160000 --- a/src/llvm +++ b/src/llvm @@ -1 +1 @@ -Subproject commit 0d999e5b315b6ff78fcea772466d985ce53fd8dc +Subproject commit 1bba09755d95892bc826c558630e93803b0a4ee6 From 8f62c30eca9b5d8f5aca4689cffd44f11217e71f Mon Sep 17 00:00:00 2001 From: Jason Thompson Date: Mon, 4 Aug 2014 16:11:17 -0400 Subject: [PATCH 2/2] Fixes to pull request #16244 - Moved examples for permutations and next into trait definition. --- src/libcollections/slice.rs | 45 ++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 55678682f2b69..62ac2b2f3528d 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -256,18 +256,6 @@ pub struct Permutations { } impl Iterator> for Permutations { - /// Returns next permuation in Iterator of all possible - /// permuations of a vector. - /// - /// # Example - /// - /// ```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()); - /// ``` #[inline] fn next(&mut self) -> Option> { match self.swaps.next() { @@ -326,6 +314,28 @@ pub trait ImmutableCloneableVector { /// 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; } @@ -347,17 +357,6 @@ impl<'a,T:Clone> ImmutableCloneableVector for &'a [T] { } /// Returns an iterator over all permutations of a vector. - /// - /// # Example - /// - /// ```rust - /// let v = [1i, 2, 3]; - /// let mut perms = v.permutations(); - /// - /// for p in perms { - /// println!("{}", p); - /// } - /// ``` fn permutations(self) -> Permutations { Permutations{ swaps: ElementSwaps::new(self.len()),