Skip to content

Commit b7e9306

Browse files
committed
auto merge of #13458 : huonw/rust/doc-signatures, r=alexcrichton
Add more type signatures to the docs; tweak a few of them. Someone reading the docs won't know what the types of various things are, so this adds them in a few meaningful places to help with comprehension. cc #13423.
2 parents 8b6091e + 5b109a1 commit b7e9306

File tree

5 files changed

+44
-27
lines changed

5 files changed

+44
-27
lines changed

src/libstd/fmt/mod.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -276,16 +276,22 @@ references information on the stack. Under the hood, all of
276276
the related macros are implemented in terms of this. First
277277
off, some example usage is:
278278
279-
```ignore
279+
```
280280
use std::fmt;
281+
use std::io;
281282
282-
# fn lol<T>() -> T { fail!() }
283-
# let my_writer: &mut ::std::io::Writer = lol();
284-
# let my_fn: fn(&fmt::Arguments) = lol();
285-
283+
# #[allow(unused_must_use)]
284+
# fn main() {
286285
format_args!(fmt::format, "this returns {}", "~str");
287-
format_args!(|args| { fmt::write(my_writer, args) }, "some {}", "args");
288-
format_args!(my_fn, "format {}", "string");
286+
287+
let some_writer: &mut io::Writer = &mut io::stdout();
288+
format_args!(|args| { fmt::write(some_writer, args) }, "print with a {}", "closure");
289+
290+
fn my_fmt_fn(args: &fmt::Arguments) {
291+
fmt::write(&mut io::stdout(), args);
292+
}
293+
format_args!(my_fmt_fn, "or a {} too", "function");
294+
# }
289295
```
290296
291297
The first argument of the `format_args!` macro is a function (or closure) which

src/libstd/io/mod.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ Some examples of obvious things you might want to do
9797
```rust
9898
# fn main() { }
9999
# fn foo() {
100-
# #[allow(unused_must_use, dead_code)];
101-
use std::io::net::tcp::TcpListener;
100+
# #![allow(dead_code)]
101+
use std::io::{TcpListener, TcpStream};
102102
use std::io::net::ip::{Ipv4Addr, SocketAddr};
103103
use std::io::{Acceptor, Listener};
104104
@@ -108,12 +108,19 @@ Some examples of obvious things you might want to do
108108
// bind the listener to the specified address
109109
let mut acceptor = listener.listen();
110110
111-
// accept connections and process them
112-
# fn handle_client<T>(_: T) {}
111+
fn handle_client(mut stream: TcpStream) {
112+
// ...
113+
# &mut stream; // silence unused mutability/variable warning
114+
}
115+
// accept connections and process them, spawning a new tasks for each one
113116
for stream in acceptor.incoming() {
114-
spawn(proc() {
115-
handle_client(stream);
116-
});
117+
match stream {
118+
Err(e) => { /* connection failed */ }
119+
Ok(stream) => spawn(proc() {
120+
// connection succeeded
121+
handle_client(stream)
122+
})
123+
}
117124
}
118125
119126
// close the socket server

src/libstd/io/net/tcp.rs

+15-9
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ impl Writer for TcpStream {
100100
/// # Example
101101
///
102102
/// ```rust
103-
/// # fn main() {}
103+
/// # fn main() { }
104104
/// # fn foo() {
105-
/// # #[allow(unused_must_use, dead_code)];
106-
/// use std::io::net::tcp::TcpListener;
105+
/// # #![allow(dead_code)]
106+
/// use std::io::{TcpListener, TcpStream};
107107
/// use std::io::net::ip::{Ipv4Addr, SocketAddr};
108108
/// use std::io::{Acceptor, Listener};
109109
///
@@ -113,12 +113,19 @@ impl Writer for TcpStream {
113113
/// // bind the listener to the specified address
114114
/// let mut acceptor = listener.listen();
115115
///
116-
/// // accept connections and process them
117-
/// # fn handle_client<T>(_: T) {}
116+
/// fn handle_client(mut stream: TcpStream) {
117+
/// // ...
118+
/// # &mut stream; // silence unused mutability/variable warning
119+
/// }
120+
/// // accept connections and process them, spawning a new tasks for each one
118121
/// for stream in acceptor.incoming() {
119-
/// spawn(proc() {
120-
/// handle_client(stream);
121-
/// });
122+
/// match stream {
123+
/// Err(e) => { /* connection failed */ }
124+
/// Ok(stream) => spawn(proc() {
125+
/// // connection succeeded
126+
/// handle_client(stream)
127+
/// })
128+
/// }
122129
/// }
123130
///
124131
/// // close the socket server
@@ -728,4 +735,3 @@ mod test {
728735
assert_eq!(s.read_to_end(), Ok(vec!(1)));
729736
})
730737
}
731-

src/libstd/sync/atomics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ pub struct AtomicOption<T> {
157157
///
158158
/// Rust's memory orderings are the same as in C++[1].
159159
///
160-
/// [1]: http://gcc.gnu.org/wiki/Atomic/GCCMM/AtomicSync
160+
/// 1: http://gcc.gnu.org/wiki/Atomic/GCCMM/AtomicSync
161161
pub enum Ordering {
162162
/// No ordering constraints, only atomic operations
163163
Relaxed,

src/libstd/unstable/finally.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@ also be used. See that function for more details.
2121
2222
```
2323
use std::unstable::finally::Finally;
24-
# fn always_run_this() {}
2524
2625
(|| {
2726
// ...
2827
}).finally(|| {
29-
always_run_this();
28+
// this code is always run
3029
})
3130
```
3231
*/
@@ -158,4 +157,3 @@ fn test_compact() {
158157
do_some_fallible_work.finally(
159158
but_always_run_this_function);
160159
}
161-

0 commit comments

Comments
 (0)