Skip to content

Commit 85e8a9b

Browse files
committed
Include feedback and try to make examples build on all channels.
1 parent c4ea700 commit 85e8a9b

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

src/libcore/borrow.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
1313
#![stable(feature = "rust1", since = "1.0.0")]
1414

15-
// impl Borrow<str> for String
16-
// impl<T> Borrow<T> for Arc<T>
17-
// impl<K> HashSet<K> { fn get<Q>(&self, q: &Q) where K: Borrow<Q> }
18-
1915
/// A trait identifying how borrowed data behaves.
2016
///
2117
/// If a type implements this trait, it signals that a reference to it behaves
@@ -26,10 +22,10 @@
2622
///
2723
/// As a consequence, this trait should only be implemented for types managing
2824
/// a value of another type without modifying its behavior. Examples are
29-
/// smart pointers such as [`Box`] or [`Rc`] as well the owned version of
30-
/// slices such as [`Vec`].
25+
/// smart pointers such as [`Box<T>`] or [`Rc<T>`] as well the owned version
26+
/// of slices such as [`Vec<T>`].
3127
///
32-
/// A relaxed version that allows providing a reference to some other type
28+
/// A relaxed version that allows converting a reference to some other type
3329
/// without any further promises is available through [`AsRef`].
3430
///
3531
/// When writing generic code, a use of `Borrow` should always be justified
@@ -41,23 +37,24 @@
4137
/// The companion trait [`BorrowMut`] provides the same guarantees for
4238
/// mutable references.
4339
///
44-
/// [`Box`]: ../boxed/struct.Box.html
45-
/// [`Rc`]: ../rc/struct.Rc.html
46-
/// [`Vec`]: ../vec/struct.Vec.html
40+
/// [`Box<T>`]: ../boxed/struct.Box.html
41+
/// [`Rc<T>`]: ../rc/struct.Rc.html
42+
/// [`Vec<T>`]: ../vec/struct.Vec.html
4743
/// [`AsRef`]: ../convert/trait.AsRef.html
4844
/// [`BorrowMut`]: trait.BorrowMut.html
4945
///
5046
/// # Examples
5147
///
52-
/// As a data collection, [`HashMap`] owns both keys and values. If the key’s
53-
/// actual data is wrapped in a managing type of some kind, it should,
54-
/// however, still be possible to search for a value using a reference to the
55-
/// key’s data. For instance, if the key is a string, then it is likely
56-
/// stored with the hash map as a [`String`], while it should be possible
57-
/// to search using a [`&str`][`str`]. Thus, `insert` needs to operate on a
58-
/// string while `get` needs to be able to use a `&str`.
48+
/// As a data collection, [`HashMap<K, V>`] owns both keys and values. If
49+
/// the key’s actual data is wrapped in a managing type of some kind, it
50+
/// should, however, still be possible to search for a value using a
51+
/// reference to the key’s data. For instance, if the key is a string, then
52+
/// it is likely stored with the hash map as a [`String`], while it should
53+
/// be possible to search using a [`&str`][`str`]. Thus, `insert` needs to
54+
/// operate on a `String` while `get` needs to be able to use a `&str`.
5955
///
60-
/// Slightly simplified, the relevant parts of `HashMap` look like this:
56+
/// Slightly simplified, the relevant parts of `HashMap<K, V>` look like
57+
/// this:
6158
///
6259
/// ```
6360
/// use std::borrow::Borrow;
@@ -70,26 +67,28 @@
7067
///
7168
/// impl<K, V> HashMap<K, V> {
7269
/// pub fn insert(&self, key: K, value: V) -> Option<V>
73-
/// where K: Hash + Eq
70+
/// where K: Hash + Eq
7471
/// {
7572
/// # unimplemented!()
7673
/// // ...
7774
/// }
7875
///
7976
/// pub fn get<Q>(&self, k: &Q) -> Option<&V>
80-
/// where K: Borrow<Q>,
81-
/// Q: Hash + Eq + ?Sized
77+
/// where
78+
/// K: Borrow<Q>,
79+
/// Q: Hash + Eq + ?Sized
8280
/// {
8381
/// # unimplemented!()
8482
/// // ...
8583
/// }
8684
/// }
8785
/// ```
8886
///
89-
/// The entire hash map is generic over the stored type for the key, `K`.
90-
/// When inserting a value, the map is given such a `K` and needs to find
91-
/// the correct hash bucket and check if the key is already present based
92-
/// on that `K` value. It therefore requires `K: Hash + Eq`.
87+
/// The entire hash map is generic over a key type `K`. Because these keys
88+
/// are stored by with the hash map, this type as to own the key’s data.
89+
/// When inserting a key-value pair, the map is given such a `K` and needs
90+
/// to find the correct hash bucket and check if the key is already present
91+
/// based on that `K`. It therefore requires `K: Hash + Eq`.
9392
///
9493
/// In order to search for a value based on the key’s data, the `get` method
9594
/// is generic over some type `Q`. Technically, it needs to convert that `Q`
@@ -103,10 +102,11 @@
103102
/// result as `Q`’s by demanding that `K: Borrow<Q>`.
104103
///
105104
/// As a consequence, the hash map breaks if a `K` wrapping a `Q` value
106-
/// produces a different hash than `Q`. For instance, image you have a
107-
/// type that wraps a string but compares ASCII letters case-insensitive:
105+
/// produces a different hash than `Q`. For instance, imagine you have a
106+
/// type that wraps a string but compares ASCII letters ignoring their case:
108107
///
109108
/// ```
109+
/// # #[allow(unused_imports)]
110110
/// use std::ascii::AsciiExt;
111111
///
112112
/// pub struct CIString(String);
@@ -121,10 +121,10 @@
121121
/// ```
122122
///
123123
/// Because two equal values need to produce the same hash value, the
124-
/// implementation of `Hash` need to reflect that, too:
124+
/// implementation of `Hash` needs to reflect that, too:
125125
///
126126
/// ```
127-
/// # use std::ascii::AsciiExt;
127+
/// # #[allow(unused_imports)] use std::ascii::AsciiExt;
128128
/// # use std::hash::{Hash, Hasher};
129129
/// # pub struct CIString(String);
130130
/// impl Hash for CIString {
@@ -145,7 +145,7 @@
145145
/// which doesn’t carry any such restrictions.
146146
///
147147
/// [`Hash`]: ../hash/trait.Hash.html
148-
/// [`HashMap`]: ../collections/struct.HashMap.html
148+
/// [`HashMap<K, V>`]: ../collections/struct.HashMap.html
149149
/// [`String`]: ../string/struct.String.html
150150
/// [`str`]: ../primitive.str.html
151151
///

0 commit comments

Comments
 (0)