Skip to content

Commit 750da68

Browse files
committed
Merge pull request #25273 from steveklabnik/second_doc_backport
Second doc backport
2 parents 83b70c2 + 957e42a commit 750da68

File tree

11 files changed

+77
-54
lines changed

11 files changed

+77
-54
lines changed

src/libcollections/string.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -950,12 +950,13 @@ impl<'a> Deref for DerefString<'a> {
950950
/// # #![feature(collections)]
951951
/// use std::string::as_string;
952952
///
953-
/// fn string_consumer(s: String) {
954-
/// assert_eq!(s, "foo".to_string());
953+
/// // Let's pretend we have a function that requires `&String`
954+
/// fn string_consumer(s: &String) {
955+
/// assert_eq!(s, "foo");
955956
/// }
956957
///
957-
/// let string = as_string("foo").clone();
958-
/// string_consumer(string);
958+
/// // Provide a `&String` from a `&str` without allocating
959+
/// string_consumer(&as_string("foo"));
959960
/// ```
960961
#[unstable(feature = "collections")]
961962
pub fn as_string<'a>(x: &'a str) -> DerefString<'a> {

src/libcollections/vec.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,7 @@ static MAX_MEMORY_SIZE: usize = isize::MAX as usize;
116116
/// stack.push(2);
117117
/// stack.push(3);
118118
///
119-
/// loop {
120-
/// let top = match stack.pop() {
121-
/// None => break, // empty
122-
/// Some(x) => x,
123-
/// };
119+
/// while let Some(top) = stack.pop() {
124120
/// // Prints 3, 2, 1
125121
/// println!("{}", top);
126122
/// }
@@ -1907,6 +1903,22 @@ impl<'a, T> Drop for DerefVec<'a, T> {
19071903
}
19081904

19091905
/// Converts a slice to a wrapper type providing a `&Vec<T>` reference.
1906+
///
1907+
/// # Examples
1908+
///
1909+
/// ```
1910+
/// # #![feature(collections)]
1911+
/// use std::vec::as_vec;
1912+
///
1913+
/// // Let's pretend we have a function that requires `&Vec<i32>`
1914+
/// fn vec_consumer(s: &Vec<i32>) {
1915+
/// assert_eq!(s, &[1, 2, 3]);
1916+
/// }
1917+
///
1918+
/// // Provide a `&Vec<i32>` from a `&[i32]` without allocating
1919+
/// let values = [1, 2, 3];
1920+
/// vec_consumer(&as_vec(&values));
1921+
/// ```
19101922
#[unstable(feature = "collections")]
19111923
pub fn as_vec<'a, T>(x: &'a [T]) -> DerefVec<'a, T> {
19121924
unsafe {

src/libcore/cell.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ impl<T> RefCell<T> {
417417
///
418418
/// let result = thread::spawn(move || {
419419
/// let c = RefCell::new(5);
420-
/// let m = c.borrow_mut();
420+
/// let m = c.borrow();
421421
///
422422
/// let b = c.borrow_mut(); // this causes a panic
423423
/// }).join();

src/libcore/convert.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,8 @@ pub trait Into<T>: Sized {
8383
/// `String` implements `From<&str>`:
8484
///
8585
/// ```
86-
/// let s = "hello";
8786
/// let string = "hello".to_string();
88-
///
89-
/// let other_string: String = From::from(s);
87+
/// let other_string = String::from("hello");
9088
///
9189
/// assert_eq!(string, other_string);
9290
/// ```

src/libcore/iter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ pub trait Iterator {
179179

180180
/// Creates an iterator that iterates over both this and the specified
181181
/// iterators simultaneously, yielding the two elements as pairs. When
182-
/// either iterator returns `None`, all further invocations of next() will
183-
/// return `None`.
182+
/// either iterator returns `None`, all further invocations of `next()`
183+
/// will return `None`.
184184
///
185185
/// # Examples
186186
///

src/libstd/io/stdio.rs

+4
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ impl Write for StderrRaw {
9595
///
9696
/// This handle implements the `Read` trait, but beware that concurrent reads
9797
/// of `Stdin` must be executed with care.
98+
///
99+
/// Created by the function `io::stdin()`.
98100
#[stable(feature = "rust1", since = "1.0.0")]
99101
pub struct Stdin {
100102
inner: Arc<Mutex<BufReader<StdinRaw>>>,
@@ -206,6 +208,8 @@ const OUT_MAX: usize = ::usize::MAX;
206208
/// Each handle shares a global buffer of data to be written to the standard
207209
/// output stream. Access is also synchronized via a lock and explicit control
208210
/// over locking is available via the `lock` method.
211+
///
212+
/// Created by the function `io::stdout()`.
209213
#[stable(feature = "rust1", since = "1.0.0")]
210214
pub struct Stdout {
211215
// FIXME: this should be LineWriter or BufWriter depending on the state of

src/libstd/net/addr.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub enum SocketAddr {
4141
#[stable(feature = "rust1", since = "1.0.0")]
4242
pub struct SocketAddrV4 { inner: libc::sockaddr_in }
4343

44-
/// An IPv6 socket address
44+
/// An IPv6 socket address.
4545
#[derive(Copy)]
4646
#[stable(feature = "rust1", since = "1.0.0")]
4747
pub struct SocketAddrV6 { inner: libc::sockaddr_in6 }
@@ -56,7 +56,7 @@ impl SocketAddr {
5656
}
5757
}
5858

59-
/// Gets the IP address associated with this socket address.
59+
/// Returns the IP address associated with this socket address.
6060
#[unstable(feature = "ip_addr", reason = "recent addition")]
6161
pub fn ip(&self) -> IpAddr {
6262
match *self {
@@ -65,7 +65,7 @@ impl SocketAddr {
6565
}
6666
}
6767

68-
/// Gets the port number associated with this socket address
68+
/// Returns the port number associated with this socket address.
6969
#[stable(feature = "rust1", since = "1.0.0")]
7070
pub fn port(&self) -> u16 {
7171
match *self {
@@ -89,15 +89,15 @@ impl SocketAddrV4 {
8989
}
9090
}
9191

92-
/// Gets the IP address associated with this socket address.
92+
/// Returns the IP address associated with this socket address.
9393
#[stable(feature = "rust1", since = "1.0.0")]
9494
pub fn ip(&self) -> &Ipv4Addr {
9595
unsafe {
9696
&*(&self.inner.sin_addr as *const libc::in_addr as *const Ipv4Addr)
9797
}
9898
}
9999

100-
/// Gets the port number associated with this socket address
100+
/// Returns the port number associated with this socket address.
101101
#[stable(feature = "rust1", since = "1.0.0")]
102102
pub fn port(&self) -> u16 { ntoh(self.inner.sin_port) }
103103
}
@@ -120,24 +120,24 @@ impl SocketAddrV6 {
120120
}
121121
}
122122

123-
/// Gets the IP address associated with this socket address.
123+
/// Returns the IP address associated with this socket address.
124124
#[stable(feature = "rust1", since = "1.0.0")]
125125
pub fn ip(&self) -> &Ipv6Addr {
126126
unsafe {
127127
&*(&self.inner.sin6_addr as *const libc::in6_addr as *const Ipv6Addr)
128128
}
129129
}
130130

131-
/// Gets the port number associated with this socket address
131+
/// Returns the port number associated with this socket address.
132132
#[stable(feature = "rust1", since = "1.0.0")]
133133
pub fn port(&self) -> u16 { ntoh(self.inner.sin6_port) }
134134

135-
/// Gets scope ID associated with this address, corresponding to the
135+
/// Returns scope ID associated with this address, corresponding to the
136136
/// `sin6_flowinfo` field in C.
137137
#[stable(feature = "rust1", since = "1.0.0")]
138138
pub fn flowinfo(&self) -> u32 { ntoh(self.inner.sin6_flowinfo) }
139139

140-
/// Gets scope ID associated with this address, corresponding to the
140+
/// Returns scope ID associated with this address, corresponding to the
141141
/// `sin6_scope_id` field in C.
142142
#[stable(feature = "rust1", since = "1.0.0")]
143143
pub fn scope_id(&self) -> u32 { ntoh(self.inner.sin6_scope_id) }

src/libstd/net/ip.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub enum Ipv6MulticastScope {
6060
impl Ipv4Addr {
6161
/// Creates a new IPv4 address from four eight-bit octets.
6262
///
63-
/// The result will represent the IP address a.b.c.d
63+
/// The result will represent the IP address `a`.`b`.`c`.`d`.
6464
#[stable(feature = "rust1", since = "1.0.0")]
6565
pub fn new(a: u8, b: u8, c: u8, d: u8) -> Ipv4Addr {
6666
Ipv4Addr {
@@ -73,19 +73,19 @@ impl Ipv4Addr {
7373
}
7474
}
7575

76-
/// Returns the four eight-bit integers that make up this address
76+
/// Returns the four eight-bit integers that make up this address.
7777
#[stable(feature = "rust1", since = "1.0.0")]
7878
pub fn octets(&self) -> [u8; 4] {
7979
let bits = ntoh(self.inner.s_addr);
8080
[(bits >> 24) as u8, (bits >> 16) as u8, (bits >> 8) as u8, bits as u8]
8181
}
8282

83-
/// Returns true for the special 'unspecified' address 0.0.0.0
83+
/// Returns true for the special 'unspecified' address 0.0.0.0.
8484
pub fn is_unspecified(&self) -> bool {
8585
self.inner.s_addr == 0
8686
}
8787

88-
/// Returns true if this is a loopback address (127.0.0.0/8)
88+
/// Returns true if this is a loopback address (127.0.0.0/8).
8989
pub fn is_loopback(&self) -> bool {
9090
self.octets()[0] == 127
9191
}
@@ -106,7 +106,7 @@ impl Ipv4Addr {
106106
}
107107
}
108108

109-
/// Returns true if the address is link-local (169.254.0.0/16)
109+
/// Returns true if the address is link-local (169.254.0.0/16).
110110
pub fn is_link_local(&self) -> bool {
111111
self.octets()[0] == 169 && self.octets()[1] == 254
112112
}
@@ -116,7 +116,7 @@ impl Ipv4Addr {
116116
/// Non-globally-routable networks include the private networks (10.0.0.0/8,
117117
/// 172.16.0.0/12 and 192.168.0.0/16), the loopback network (127.0.0.0/8),
118118
/// the link-local network (169.254.0.0/16), the broadcast address (255.255.255.255/32) and
119-
/// the test networks used for documentation (192.0.2.0/24, 198.51.100.0/24 and 203.0.113.0/24)
119+
/// the test networks used for documentation (192.0.2.0/24, 198.51.100.0/24 and 203.0.113.0/24).
120120
pub fn is_global(&self) -> bool {
121121
!self.is_private() && !self.is_loopback() && !self.is_link_local() &&
122122
!self.is_broadcast() && !self.is_documentation()
@@ -131,13 +131,13 @@ impl Ipv4Addr {
131131

132132
/// Returns true if this is a broadcast address.
133133
///
134-
/// A broadcast address has all octets set to 255 as defined in RFC 919
134+
/// A broadcast address has all octets set to 255 as defined in RFC 919.
135135
pub fn is_broadcast(&self) -> bool {
136136
self.octets()[0] == 255 && self.octets()[1] == 255 &&
137137
self.octets()[2] == 255 && self.octets()[3] == 255
138138
}
139139

140-
/// Returns true if this address is in a range designated for documentation
140+
/// Returns true if this address is in a range designated for documentation.
141141
///
142142
/// This is defined in RFC 5737
143143
/// - 192.0.2.0/24 (TEST-NET-1)
@@ -152,7 +152,7 @@ impl Ipv4Addr {
152152
}
153153
}
154154

155-
/// Converts this address to an IPv4-compatible IPv6 address
155+
/// Converts this address to an IPv4-compatible IPv6 address.
156156
///
157157
/// a.b.c.d becomes ::a.b.c.d
158158
#[stable(feature = "rust1", since = "1.0.0")]
@@ -162,7 +162,7 @@ impl Ipv4Addr {
162162
((self.octets()[2] as u16) << 8) | self.octets()[3] as u16)
163163
}
164164

165-
/// Converts this address to an IPv4-mapped IPv6 address
165+
/// Converts this address to an IPv4-mapped IPv6 address.
166166
///
167167
/// a.b.c.d becomes ::ffff:a.b.c.d
168168
#[stable(feature = "rust1", since = "1.0.0")]
@@ -247,7 +247,7 @@ impl FromInner<libc::in_addr> for Ipv4Addr {
247247
impl Ipv6Addr {
248248
/// Creates a new IPv6 address from eight 16-bit segments.
249249
///
250-
/// The result will represent the IP address a:b:c:d:e:f:g:h
250+
/// The result will represent the IP address a:b:c:d:e:f:g:h.
251251
#[stable(feature = "rust1", since = "1.0.0")]
252252
pub fn new(a: u16, b: u16, c: u16, d: u16, e: u16, f: u16, g: u16,
253253
h: u16) -> Ipv6Addr {
@@ -259,7 +259,7 @@ impl Ipv6Addr {
259259
}
260260
}
261261

262-
/// Returns the eight 16-bit segments that make up this address
262+
/// Returns the eight 16-bit segments that make up this address.
263263
#[stable(feature = "rust1", since = "1.0.0")]
264264
pub fn segments(&self) -> [u16; 8] {
265265
[ntoh(self.inner.s6_addr[0]),
@@ -272,12 +272,12 @@ impl Ipv6Addr {
272272
ntoh(self.inner.s6_addr[7])]
273273
}
274274

275-
/// Returns true for the special 'unspecified' address ::
275+
/// Returns true for the special 'unspecified' address ::.
276276
pub fn is_unspecified(&self) -> bool {
277277
self.segments() == [0, 0, 0, 0, 0, 0, 0, 0]
278278
}
279279

280-
/// Returns true if this is a loopback address (::1)
280+
/// Returns true if this is a loopback address (::1).
281281
pub fn is_loopback(&self) -> bool {
282282
self.segments() == [0, 0, 0, 0, 0, 0, 0, 1]
283283
}
@@ -295,25 +295,25 @@ impl Ipv6Addr {
295295
}
296296
}
297297

298-
/// Returns true if this is a unique local address (IPv6)
298+
/// Returns true if this is a unique local address (IPv6).
299299
///
300-
/// Unique local addresses are defined in RFC4193 and have the form fc00::/7
300+
/// Unique local addresses are defined in RFC4193 and have the form fc00::/7.
301301
pub fn is_unique_local(&self) -> bool {
302302
(self.segments()[0] & 0xfe00) == 0xfc00
303303
}
304304

305-
/// Returns true if the address is unicast and link-local (fe80::/10)
305+
/// Returns true if the address is unicast and link-local (fe80::/10).
306306
pub fn is_unicast_link_local(&self) -> bool {
307307
(self.segments()[0] & 0xffc0) == 0xfe80
308308
}
309309

310310
/// Returns true if this is a deprecated unicast site-local address (IPv6
311-
/// fec0::/10)
311+
/// fec0::/10).
312312
pub fn is_unicast_site_local(&self) -> bool {
313313
(self.segments()[0] & 0xffc0) == 0xfec0
314314
}
315315

316-
/// Returns true if the address is a globally routable unicast address
316+
/// Returns true if the address is a globally routable unicast address.
317317
///
318318
/// Non-globally-routable unicast addresses include the loopback address,
319319
/// the link-local addresses, the deprecated site-local addresses and the

src/libstd/net/tcp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl TcpStream {
125125
self.0.duplicate().map(TcpStream)
126126
}
127127

128-
/// Sets the nodelay flag on this connection to the boolean specified
128+
/// Sets the nodelay flag on this connection to the boolean specified.
129129
pub fn set_nodelay(&self, nodelay: bool) -> io::Result<()> {
130130
self.0.set_nodelay(nodelay)
131131
}

src/libstd/net/udp.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ pub struct UdpSocket(net_imp::UdpSocket);
5050
impl UdpSocket {
5151
/// Creates a UDP socket from the given address.
5252
///
53-
/// Address type can be any implementor of `ToSocketAddr` trait. See its
54-
/// documentation for concrete examples.
53+
/// The address type can be any implementor of `ToSocketAddr` trait. See
54+
/// its documentation for concrete examples.
5555
#[stable(feature = "rust1", since = "1.0.0")]
5656
pub fn bind<A: ToSocketAddrs>(addr: A) -> io::Result<UdpSocket> {
5757
super::each_addr(addr, net_imp::UdpSocket::bind).map(UdpSocket)
@@ -64,8 +64,8 @@ impl UdpSocket {
6464
self.0.recv_from(buf)
6565
}
6666

67-
/// Sends data on the socket to the given address. Returns nothing on
68-
/// success.
67+
/// Sends data on the socket to the given address. On success, returns the
68+
/// number of bytes written.
6969
///
7070
/// Address type can be any implementor of `ToSocketAddrs` trait. See its
7171
/// documentation for concrete examples.
@@ -95,34 +95,34 @@ impl UdpSocket {
9595
self.0.duplicate().map(UdpSocket)
9696
}
9797

98-
/// Sets the broadcast flag on or off
98+
/// Sets the broadcast flag on or off.
9999
pub fn set_broadcast(&self, on: bool) -> io::Result<()> {
100100
self.0.set_broadcast(on)
101101
}
102102

103-
/// Sets the multicast loop flag to the specified value
103+
/// Sets the multicast loop flag to the specified value.
104104
///
105105
/// This lets multicast packets loop back to local sockets (if enabled)
106106
pub fn set_multicast_loop(&self, on: bool) -> io::Result<()> {
107107
self.0.set_multicast_loop(on)
108108
}
109109

110-
/// Joins a multicast IP address (becomes a member of it)
110+
/// Joins a multicast IP address (becomes a member of it).
111111
pub fn join_multicast(&self, multi: &IpAddr) -> io::Result<()> {
112112
self.0.join_multicast(multi)
113113
}
114114

115-
/// Leaves a multicast IP address (drops membership from it)
115+
/// Leaves a multicast IP address (drops membership from it).
116116
pub fn leave_multicast(&self, multi: &IpAddr) -> io::Result<()> {
117117
self.0.leave_multicast(multi)
118118
}
119119

120-
/// Sets the multicast TTL
120+
/// Sets the multicast TTL.
121121
pub fn set_multicast_time_to_live(&self, ttl: i32) -> io::Result<()> {
122122
self.0.multicast_time_to_live(ttl)
123123
}
124124

125-
/// Sets this socket's TTL
125+
/// Sets this socket's TTL.
126126
pub fn set_time_to_live(&self, ttl: i32) -> io::Result<()> {
127127
self.0.time_to_live(ttl)
128128
}

0 commit comments

Comments
 (0)