Skip to content

Rollup of 9 pull requests #32172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e36c7da
Clarify documentation of `hash::SipHasher`
dirk Mar 7, 2016
054196d
Amend `hash::SipHasher` docs to more strongly discourage cryptographi…
dirk Mar 7, 2016
d7e406e
Remove final note from testing chapter.
pyfisch Mar 8, 2016
99eee83
Add missing documentation examples for BTreeSet.
nathankleyn Mar 8, 2016
118b975
Add missing documentation examples for BinaryHeap.
nathankleyn Mar 8, 2016
46dc35e
Link to actual CSPRNG in `hash::SipHasher` documentation
dirk Mar 9, 2016
df550de
Clarify that try_unwrap needs exactly one
steveklabnik Mar 9, 2016
0f426aa
Small grammar fix in Guessing Game
steveklabnik Mar 9, 2016
aaca317
Add other primitive types to the reference
steveklabnik Mar 9, 2016
7848469
Remove inaccurate claim about inline assembly
steveklabnik Mar 9, 2016
04436fb
Address review comments to add "basic usage" sections to docs.
nathankleyn Mar 9, 2016
d9dba76
Prefer 'associated function' over 'static method' in msg.
frewsxcv Feb 23, 2016
7d7df8d
Rollup merge of #31830 - frewsxcv:assoc-func, r=steveklabnik
steveklabnik Mar 10, 2016
a885267
Rollup merge of #32091 - dirk:dirk/siphasher-docs-clarification, r=al…
steveklabnik Mar 10, 2016
e85d9b1
Rollup merge of #32125 - pyfisch:patch-2, r=steveklabnik
steveklabnik Mar 10, 2016
5926108
Rollup merge of #32136 - nathankleyn:improve-docs-for-btreeset, r=ste…
steveklabnik Mar 10, 2016
92958be
Rollup merge of #32137 - nathankleyn:improve-docs-for-binaryheap, r=s…
steveklabnik Mar 10, 2016
57db26a
Rollup merge of #32147 - steveklabnik:gh31950, r=bluss
steveklabnik Mar 10, 2016
7338111
Rollup merge of #32148 - steveklabnik:gh31912, r=apasel422
steveklabnik Mar 10, 2016
00da4dc
Rollup merge of #32149 - steveklabnik:gh31628, r=bluss
steveklabnik Mar 10, 2016
ce16a5d
Rollup merge of #32150 - steveklabnik:gh20213, r=bluss
steveklabnik Mar 10, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/doc/book/guessing-game.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ Rust warns us that we haven’t used the `Result` value. This warning comes from
a special annotation that `io::Result` has. Rust is trying to tell you that
you haven’t handled a possible error. The right way to suppress the error is
to actually write error handling. Luckily, if we want to crash if there’s
a problem, we can use these two little methods. If we can recover from the
a problem, we can use `expect()`. If we can recover from the
error somehow, we’d do something else, but we’ll save that for a future
project.

Expand Down
3 changes: 1 addition & 2 deletions src/doc/book/inline-assembly.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

For extremely low-level manipulations and performance reasons, one
might wish to control the CPU directly. Rust supports using inline
assembly to do this via the `asm!` macro. The syntax roughly matches
that of GCC & Clang:
assembly to do this via the `asm!` macro.

```ignore
asm!(assembly template
Expand Down
4 changes: 0 additions & 4 deletions src/doc/book/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,3 @@ you add more examples.

We haven’t covered all of the details with writing documentation tests. For more,
please see the [Documentation chapter](documentation.html).

One final note: documentation tests *cannot* be run on binary crates.
To see more on file arrangement see the [Crates and
Modules](crates-and-modules.html) section.
4 changes: 4 additions & 0 deletions src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -3328,6 +3328,10 @@ The primitive types are the following:
* The boolean type `bool` with values `true` and `false`.
* The machine types (integer and floating-point).
* The machine-dependent integer types.
* Arrays
* Tuples
* Slices
* Function pointers

#### Machine types

Expand Down
5 changes: 3 additions & 2 deletions src/liballoc/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,12 @@ impl<T> Arc<T> {
Arc { _ptr: unsafe { Shared::new(Box::into_raw(x)) } }
}

/// Unwraps the contained value if the `Arc<T>` has only one strong reference.
/// This will succeed even if there are outstanding weak references.
/// Unwraps the contained value if the `Arc<T>` has exactly one strong reference.
///
/// Otherwise, an `Err` is returned with the same `Arc<T>`.
///
/// This will succeed even if there are outstanding weak references.
///
/// # Examples
///
/// ```
Expand Down
5 changes: 3 additions & 2 deletions src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,12 @@ impl<T> Rc<T> {
}
}

/// Unwraps the contained value if the `Rc<T>` has only one strong reference.
/// This will succeed even if there are outstanding weak references.
/// Unwraps the contained value if the `Rc<T>` has exactly one strong reference.
///
/// Otherwise, an `Err` is returned with the same `Rc<T>`.
///
/// This will succeed even if there are outstanding weak references.
///
/// # Examples
///
/// ```
Expand Down
144 changes: 144 additions & 0 deletions src/libcollections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,49 @@ use vec::{self, Vec};
/// item's ordering relative to any other item, as determined by the `Ord`
/// trait, changes while it is in the heap. This is normally only possible
/// through `Cell`, `RefCell`, global state, I/O, or unsafe code.
///
/// # Examples
///
/// ```
/// use std::collections::BinaryHeap;
///
/// // type inference lets us omit an explicit type signature (which
/// // would be `BinaryHeap<i32>` in this example).
/// let mut heap = BinaryHeap::new();
///
/// // We can use peek to look at the next item in the heap. In this case,
/// // there's no items in there yet so we get None.
/// assert_eq!(heap.peek(), None);
///
/// // Let's add some scores...
/// heap.push(1);
/// heap.push(5);
/// heap.push(2);
///
/// // Now peek shows the most important item in the heap.
/// assert_eq!(heap.peek(), Some(&5));
///
/// // We can check the length of a heap.
/// assert_eq!(heap.len(), 3);
///
/// // We can iterate over the items in the heap, although they are returned in
/// // a random order.
/// for x in heap.iter() {
/// println!("{}", x);
/// }
///
/// // If we instead pop these scores, they should come back in order.
/// assert_eq!(heap.pop(), Some(5));
/// assert_eq!(heap.pop(), Some(2));
/// assert_eq!(heap.pop(), Some(1));
/// assert_eq!(heap.pop(), None);
///
/// // We can clear the heap of any remaining items.
/// heap.clear();
///
/// // The heap should now be empty.
/// assert!(heap.is_empty())
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub struct BinaryHeap<T> {
data: Vec<T>,
Expand Down Expand Up @@ -203,6 +246,8 @@ impl<T: Ord> BinaryHeap<T> {
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// use std::collections::BinaryHeap;
/// let mut heap = BinaryHeap::new();
Expand All @@ -220,6 +265,8 @@ impl<T: Ord> BinaryHeap<T> {
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// use std::collections::BinaryHeap;
/// let mut heap = BinaryHeap::with_capacity(10);
Expand All @@ -235,6 +282,8 @@ impl<T: Ord> BinaryHeap<T> {
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// use std::collections::BinaryHeap;
/// let heap = BinaryHeap::from(vec![1, 2, 3, 4]);
Expand All @@ -253,6 +302,8 @@ impl<T: Ord> BinaryHeap<T> {
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// use std::collections::BinaryHeap;
/// let mut heap = BinaryHeap::new();
Expand All @@ -273,6 +324,8 @@ impl<T: Ord> BinaryHeap<T> {
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// use std::collections::BinaryHeap;
/// let mut heap = BinaryHeap::with_capacity(100);
Expand All @@ -297,6 +350,8 @@ impl<T: Ord> BinaryHeap<T> {
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// use std::collections::BinaryHeap;
/// let mut heap = BinaryHeap::new();
Expand All @@ -318,6 +373,8 @@ impl<T: Ord> BinaryHeap<T> {
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// use std::collections::BinaryHeap;
/// let mut heap = BinaryHeap::new();
Expand All @@ -331,6 +388,19 @@ impl<T: Ord> BinaryHeap<T> {
}

/// Discards as much additional capacity as possible.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// use std::collections::BinaryHeap;
/// let mut heap: BinaryHeap<i32> = BinaryHeap::with_capacity(100);
///
/// assert!(heap.capacity() >= 100);
/// heap.shrink_to_fit();
/// assert!(heap.capacity() == 0);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn shrink_to_fit(&mut self) {
self.data.shrink_to_fit();
Expand All @@ -341,6 +411,8 @@ impl<T: Ord> BinaryHeap<T> {
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// use std::collections::BinaryHeap;
/// let mut heap = BinaryHeap::from(vec![1, 3]);
Expand All @@ -364,6 +436,8 @@ impl<T: Ord> BinaryHeap<T> {
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// use std::collections::BinaryHeap;
/// let mut heap = BinaryHeap::new();
Expand All @@ -386,6 +460,8 @@ impl<T: Ord> BinaryHeap<T> {
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// #![feature(binary_heap_extras)]
///
Expand Down Expand Up @@ -424,6 +500,8 @@ impl<T: Ord> BinaryHeap<T> {
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// #![feature(binary_heap_extras)]
///
Expand Down Expand Up @@ -454,6 +532,8 @@ impl<T: Ord> BinaryHeap<T> {
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// use std::collections::BinaryHeap;
/// let heap = BinaryHeap::from(vec![1, 2, 3, 4, 5, 6, 7]);
Expand All @@ -474,6 +554,8 @@ impl<T: Ord> BinaryHeap<T> {
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// use std::collections::BinaryHeap;
///
Expand Down Expand Up @@ -571,12 +653,40 @@ impl<T: Ord> BinaryHeap<T> {
}

/// Returns the length of the binary heap.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// use std::collections::BinaryHeap;
/// let mut heap = BinaryHeap::from(vec![1, 3]);
///
/// assert_eq!(heap.len(), 2);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn len(&self) -> usize {
self.data.len()
}

/// Checks if the binary heap is empty.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// use std::collections::BinaryHeap;
/// let mut heap = BinaryHeap::new();
///
/// assert!(heap.is_empty());
///
/// heap.push(3);
/// heap.push(5);
/// heap.push(1);
///
/// assert!(!heap.is_empty());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_empty(&self) -> bool {
self.len() == 0
Expand All @@ -585,13 +695,45 @@ impl<T: Ord> BinaryHeap<T> {
/// Clears the binary heap, returning an iterator over the removed elements.
///
/// The elements are removed in arbitrary order.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// use std::collections::BinaryHeap;
/// let mut heap = BinaryHeap::from(vec![1, 3]);
///
/// assert!(!heap.is_empty());
///
/// for x in heap.drain() {
/// println!("{}", x);
/// }
///
/// assert!(heap.is_empty());
/// ```
#[inline]
#[stable(feature = "drain", since = "1.6.0")]
pub fn drain(&mut self) -> Drain<T> {
Drain { iter: self.data.drain(..) }
}

/// Drops all items from the binary heap.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// use std::collections::BinaryHeap;
/// let mut heap = BinaryHeap::from(vec![1, 3]);
///
/// assert!(!heap.is_empty());
///
/// heap.clear();
///
/// assert!(heap.is_empty());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn clear(&mut self) {
self.drain();
Expand Down Expand Up @@ -809,6 +951,8 @@ impl<T: Ord> IntoIterator for BinaryHeap<T> {
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// use std::collections::BinaryHeap;
/// let heap = BinaryHeap::from(vec![1, 2, 3, 4]);
Expand Down
30 changes: 30 additions & 0 deletions src/libcollections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,36 @@ use Bound;
/// [`Ord`]: ../../core/cmp/trait.Ord.html
/// [`Cell`]: ../../std/cell/struct.Cell.html
/// [`RefCell`]: ../../std/cell/struct.RefCell.html
///
/// # Examples
///
/// ```
/// use std::collections::BTreeSet;
///
/// // Type inference lets us omit an explicit type signature (which
/// // would be `BTreeSet<&str>` in this example).
/// let mut books = BTreeSet::new();
///
/// // Add some books.
/// books.insert("A Dance With Dragons");
/// books.insert("To Kill a Mockingbird");
/// books.insert("The Odyssey");
/// books.insert("The Great Gatsby");
///
/// // Check for a specific one.
/// if !books.contains("The Winds of Winter") {
/// println!("We have {} books, but The Winds of Winter ain't one.",
/// books.len());
/// }
///
/// // Remove a book.
/// books.remove("The Odyssey");
///
/// // Iterate over everything.
/// for book in &books {
/// println!("{}", book);
/// }
/// ```
#[derive(Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct BTreeSet<T> {
Expand Down
Loading