Skip to content

Rollup of 7 pull requests #38407

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 22 commits into from
Closed
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9976f5f
Add missing doc examples for SocketAddr struct
GuillaumeGomez Dec 8, 2016
7fe17f9
Add doc examples for UnixStream
GuillaumeGomez Dec 8, 2016
c35b9f6
Add UnixListener doc examples
GuillaumeGomez Dec 8, 2016
a78a33c
Add Incoming doc examples
GuillaumeGomez Dec 8, 2016
ce1fbad
Rewrite, improve documentation for `core::hash::BuildHasherDefault`.
frewsxcv Dec 13, 2016
8323185
minor fix about visibility in reference
liigo Dec 7, 2016
e095c71
Associated items and variants inherit visibility from their traits an…
liigo Dec 13, 2016
16d4b7b
doc: Explain meaning of Result iters and link to factory functions.
sourcefrog Dec 3, 2016
60fbe7a
Add missing Duration examples
GuillaumeGomez Dec 13, 2016
cf56c1f
Indicate `BTreeSet` in docs is code-like.
frewsxcv Dec 7, 2016
ae36934
Document how `BTreeSet` iterator structures are created.
frewsxcv Dec 7, 2016
4c4e8c4
Simplify `BTreeSet::iter` doc example.
frewsxcv Dec 7, 2016
b4ed584
Indicate that `BTreeSet::iter` returns values in ascending order.
frewsxcv Dec 7, 2016
8cd3081
rustdoc: a formatting nit
tshepang Dec 15, 2016
2938e6a
Add missing doc examples for UnixDatagram
GuillaumeGomez Dec 8, 2016
0d4772e
Rollup merge of #38158 - sourcefrog:doc-iter, r=GuillaumeGomez
GuillaumeGomez Dec 16, 2016
558b71a
Rollup merge of #38208 - frewsxcv:btreesetdocs, r=GuillaumeGomez
GuillaumeGomez Dec 16, 2016
2ed1349
Rollup merge of #38215 - liigo:patch-12, r=petrochenkov
GuillaumeGomez Dec 16, 2016
269978e
Rollup merge of #38236 - GuillaumeGomez:unix_socket_doc, r=frewsxcv
GuillaumeGomez Dec 16, 2016
5f1f0e1
Rollup merge of #38334 - frewsxcv:BuildHasherDefault, r=GuillaumeGomez
GuillaumeGomez Dec 16, 2016
9af8a23
Rollup merge of #38346 - GuillaumeGomez:duration_doc, r=frewsxcv
GuillaumeGomez Dec 16, 2016
71ce557
Rollup merge of #38395 - tshepang:nit, r=steveklabnik
GuillaumeGomez Dec 16, 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
3 changes: 2 additions & 1 deletion src/doc/reference.md
Original file line number Diff line number Diff line change
@@ -1731,7 +1731,8 @@ of an item to see whether it should be allowed or not. This is where privacy
warnings are generated, or otherwise "you used a private item of another module
and weren't allowed to."

By default, everything in Rust is *private*, with one exception. Enum variants
By default, everything in Rust is *private*, with two exceptions: Associated
items in a `pub` Trait are public by default; Enum variants
in a `pub` enum are also public by default. When an item is declared as `pub`,
it can be thought of as being accessible to the outside world. For example:

69 changes: 58 additions & 11 deletions src/libcollections/btree/set.rs
Original file line number Diff line number Diff line change
@@ -74,53 +74,89 @@ pub struct BTreeSet<T> {
map: BTreeMap<T, ()>,
}

/// An iterator over a BTreeSet's items.
/// An iterator over a `BTreeSet`'s items.
///
/// This structure is created by the [`iter`] method on [`BTreeSet`].
///
/// [`BTreeSet`]: struct.BTreeSet.html
/// [`iter`]: struct.BTreeSet.html#method.iter
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Iter<'a, T: 'a> {
iter: Keys<'a, T, ()>,
}

/// An owning iterator over a BTreeSet's items.
/// An owning iterator over a `BTreeSet`'s items.
///
/// This structure is created by the `into_iter` method on [`BTreeSet`]
/// [`BTreeSet`] (provided by the `IntoIterator` trait).
///
/// [`BTreeSet`]: struct.BTreeSet.html
#[stable(feature = "rust1", since = "1.0.0")]
pub struct IntoIter<T> {
iter: ::btree_map::IntoIter<T, ()>,
}

/// An iterator over a sub-range of BTreeSet's items.
/// An iterator over a sub-range of `BTreeSet`'s items.
///
/// This structure is created by the [`range`] method on [`BTreeSet`].
///
/// [`BTreeSet`]: struct.BTreeSet.html
/// [`range`]: struct.BTreeSet.html#method.range
pub struct Range<'a, T: 'a> {
iter: ::btree_map::Range<'a, T, ()>,
}

/// A lazy iterator producing elements in the set difference (in-order).
///
/// This structure is created by the [`difference`] method on [`BTreeSet`].
///
/// [`BTreeSet`]: struct.BTreeSet.html
/// [`difference`]: struct.BTreeSet.html#method.difference
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Difference<'a, T: 'a> {
a: Peekable<Iter<'a, T>>,
b: Peekable<Iter<'a, T>>,
}

/// A lazy iterator producing elements in the set symmetric difference (in-order).
///
/// This structure is created by the [`symmetric_difference`] method on
/// [`BTreeSet`].
///
/// [`BTreeSet`]: struct.BTreeSet.html
/// [`symmetric_difference`]: struct.BTreeSet.html#method.symmetric_difference
#[stable(feature = "rust1", since = "1.0.0")]
pub struct SymmetricDifference<'a, T: 'a> {
a: Peekable<Iter<'a, T>>,
b: Peekable<Iter<'a, T>>,
}

/// A lazy iterator producing elements in the set intersection (in-order).
///
/// This structure is created by the [`intersection`] method on [`BTreeSet`].
///
/// [`BTreeSet`]: struct.BTreeSet.html
/// [`intersection`]: struct.BTreeSet.html#method.intersection
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Intersection<'a, T: 'a> {
a: Peekable<Iter<'a, T>>,
b: Peekable<Iter<'a, T>>,
}

/// A lazy iterator producing elements in the set union (in-order).
///
/// This structure is created by the [`union`] method on [`BTreeSet`].
///
/// [`BTreeSet`]: struct.BTreeSet.html
/// [`union`]: struct.BTreeSet.html#method.union
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Union<'a, T: 'a> {
a: Peekable<Iter<'a, T>>,
b: Peekable<Iter<'a, T>>,
}

impl<T: Ord> BTreeSet<T> {
/// Makes a new BTreeSet with a reasonable choice of B.
/// Makes a new `BTreeSet` with a reasonable choice of B.
///
/// # Examples
///
@@ -137,21 +173,32 @@ impl<T: Ord> BTreeSet<T> {
}

impl<T> BTreeSet<T> {
/// Gets an iterator over the BTreeSet's contents.
/// Gets an iterator that visits the values in the `BTreeSet` in ascending order.
///
/// # Examples
///
/// ```
/// use std::collections::BTreeSet;
///
/// let set: BTreeSet<usize> = [1, 2, 3, 4].iter().cloned().collect();
/// let set: BTreeSet<usize> = [1, 2, 3].iter().cloned().collect();
/// let mut set_iter = set.iter();
/// assert_eq!(set_iter.next(), Some(&1));
/// assert_eq!(set_iter.next(), Some(&2));
/// assert_eq!(set_iter.next(), Some(&3));
/// assert_eq!(set_iter.next(), None);
/// ```
///
/// for x in set.iter() {
/// println!("{}", x);
/// }
/// Values returned by the iterator are returned in ascending order:
///
/// let v: Vec<_> = set.iter().cloned().collect();
/// assert_eq!(v, [1, 2, 3, 4]);
/// ```
/// use std::collections::BTreeSet;
///
/// let set: BTreeSet<usize> = [3, 1, 2].iter().cloned().collect();
/// let mut set_iter = set.iter();
/// assert_eq!(set_iter.next(), Some(&1));
/// assert_eq!(set_iter.next(), Some(&2));
/// assert_eq!(set_iter.next(), Some(&3));
/// assert_eq!(set_iter.next(), None);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter(&self) -> Iter<T> {
40 changes: 37 additions & 3 deletions src/libcore/hash/mod.rs
Original file line number Diff line number Diff line change
@@ -255,10 +255,44 @@ pub trait BuildHasher {
fn build_hasher(&self) -> Self::Hasher;
}

/// A structure which implements `BuildHasher` for all `Hasher` types which also
/// implement `Default`.
/// The `BuildHasherDefault` structure is used in scenarios where one has a
/// type that implements [`Hasher`] and [`Default`], but needs that type to
/// implement [`BuildHasher`].
///
/// This struct is 0-sized and does not need construction.
/// This structure is zero-sized and does not need construction.
///
/// # Examples
///
/// Using `BuildHasherDefault` to specify a custom [`BuildHasher`] for
/// [`HashMap`]:
///
/// ```
/// use std::collections::HashMap;
/// use std::hash::{BuildHasherDefault, Hasher};
///
/// #[derive(Default)]
/// struct MyHasher;
///
/// impl Hasher for MyHasher {
/// fn write(&mut self, bytes: &[u8]) {
/// // Your hashing algorithm goes here!
/// unimplemented!()
/// }
///
/// fn finish(&self) -> u64 {
/// // Your hashing algorithm goes here!
/// unimplemented!()
/// }
/// }
///
/// type MyBuildHasher = BuildHasherDefault<SomeHasher>;
///
/// let hash_map = HashMap::<u32, u32, SomeBuidHasher>::default();
/// ```
///
/// [`BuildHasher`]: trait.BuildHasher.html
/// [`Default`]: ../default/trait.Default.html
/// [`Hasher`]: trait.Hasher.html
#[stable(since = "1.7.0", feature = "build_hasher")]
pub struct BuildHasherDefault<H>(marker::PhantomData<H>);

29 changes: 26 additions & 3 deletions src/libcore/result.rs
Original file line number Diff line number Diff line change
@@ -501,6 +501,8 @@ impl<T, E> Result<T, E> {

/// Returns an iterator over the possibly contained value.
///
/// The iterator yields one value if the result is [`Ok`], otherwise none.
///
/// # Examples
///
/// Basic usage:
@@ -512,6 +514,8 @@ impl<T, E> Result<T, E> {
/// let x: Result<u32, &str> = Err("nothing!");
/// assert_eq!(x.iter().next(), None);
/// ```
///
/// [`Ok`]: enum.Result.html#variant.Ok
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter(&self) -> Iter<T> {
@@ -520,6 +524,8 @@ impl<T, E> Result<T, E> {

/// Returns a mutable iterator over the possibly contained value.
///
/// The iterator yields one value if the result is [`Ok`], otherwise none.
///
/// # Examples
///
/// Basic usage:
@@ -535,6 +541,8 @@ impl<T, E> Result<T, E> {
/// let mut x: Result<u32, &str> = Err("nothing!");
/// assert_eq!(x.iter_mut().next(), None);
/// ```
///
/// [`Ok`]: enum.Result.html#variant.Ok
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter_mut(&mut self) -> IterMut<T> {
@@ -848,6 +856,8 @@ impl<T, E> IntoIterator for Result<T, E> {

/// Returns a consuming iterator over the possibly contained value.
///
/// The iterator yields one value if the result is [`Ok`], otherwise none.
///
/// # Examples
///
/// Basic usage:
@@ -861,6 +871,8 @@ impl<T, E> IntoIterator for Result<T, E> {
/// let v: Vec<u32> = x.into_iter().collect();
/// assert_eq!(v, []);
/// ```
///
/// [`Ok`]: enum.Result.html#variant.Ok
#[inline]
fn into_iter(self) -> IntoIter<T> {
IntoIter { inner: self.ok() }
@@ -893,8 +905,13 @@ impl<'a, T, E> IntoIterator for &'a mut Result<T, E> {

/// An iterator over a reference to the [`Ok`] variant of a [`Result`].
///
/// The iterator yields one value if the result is [`Ok`], otherwise none.
///
/// Created by [`Result::iter`].
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Result`]: enum.Result.html
/// [`Result::iter`]: enum.Result.html#method.iter
#[derive(Debug)]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Iter<'a, T: 'a> { inner: Option<&'a T> }
@@ -934,8 +951,11 @@ impl<'a, T> Clone for Iter<'a, T> {

/// An iterator over a mutable reference to the [`Ok`] variant of a [`Result`].
///
/// Created by [`Result::iter_mut`].
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Result`]: enum.Result.html
/// [`Result::iter_mut`]: enum.Result.html#method.iter_mut
#[derive(Debug)]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct IterMut<'a, T: 'a> { inner: Option<&'a mut T> }
@@ -968,9 +988,12 @@ impl<'a, T> FusedIterator for IterMut<'a, T> {}
#[unstable(feature = "trusted_len", issue = "37572")]
unsafe impl<'a, A> TrustedLen for IterMut<'a, A> {}

/// An iterator over the value in a [`Ok`] variant of a [`Result`]. This struct is
/// created by the [`into_iter`] method on [`Result`][`Result`] (provided by
/// the [`IntoIterator`] trait).
/// An iterator over the value in a [`Ok`] variant of a [`Result`].
///
/// The iterator yields one value if the result is [`Ok`], otherwise none.
///
/// This struct is created by the [`into_iter`] method on
/// [`Result`][`Result`] (provided by the [`IntoIterator`] trait).
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Result`]: enum.Result.html
5 changes: 3 additions & 2 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
@@ -259,10 +259,11 @@ pub fn main_args(args: &[String]) -> isize {
}

let external_html = match ExternalHtml::load(
&matches.opt_strs("html-in-header"), &matches.opt_strs("html-before-content"),
&matches.opt_strs("html-in-header"),
&matches.opt_strs("html-before-content"),
&matches.opt_strs("html-after-content")) {
Some(eh) => eh,
None => return 3
None => return 3,
};
let crate_name = matches.opt_str("crate-name");
let playground_url = matches.opt_str("playground-url");
Loading