Skip to content
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

Add more type signatures to the docs; tweak a few of them. #13458

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 13 additions & 7 deletions src/libstd/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,16 +276,22 @@ references information on the stack. Under the hood, all of
the related macros are implemented in terms of this. First
off, some example usage is:

```ignore
```
use std::fmt;
use std::io;

# fn lol<T>() -> T { fail!() }
# let my_writer: &mut ::std::io::Writer = lol();
# let my_fn: fn(&fmt::Arguments) = lol();

# #[allow(unused_must_use)]
# fn main() {
format_args!(fmt::format, "this returns {}", "~str");
format_args!(|args| { fmt::write(my_writer, args) }, "some {}", "args");
format_args!(my_fn, "format {}", "string");

let some_writer: &mut io::Writer = &mut io::stdout();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be my_writer?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, unfortunately this test case was ignored so it wasn't picked up automatically. (Both the misnaming and the ignore have been fixed.)

format_args!(|args| { fmt::write(some_writer, args) }, "print with a {}", "closure");

fn my_fmt_fn(args: &fmt::Arguments) {
fmt::write(&mut io::stdout(), args);
}
format_args!(my_fmt_fn, "or a {} too", "function");
# }
```

The first argument of the `format_args!` macro is a function (or closure) which
Expand Down
21 changes: 14 additions & 7 deletions src/libstd/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ Some examples of obvious things you might want to do
```rust
# fn main() { }
# fn foo() {
# #[allow(unused_must_use, dead_code)];
use std::io::net::tcp::TcpListener;
# #![allow(dead_code)]
use std::io::{TcpListener, TcpStream};
use std::io::net::ip::{Ipv4Addr, SocketAddr};
use std::io::{Acceptor, Listener};

Expand All @@ -108,12 +108,19 @@ Some examples of obvious things you might want to do
// bind the listener to the specified address
let mut acceptor = listener.listen();

// accept connections and process them
# fn handle_client<T>(_: T) {}
fn handle_client(mut stream: TcpStream) {
// ...
# &mut stream; // silence unused mutability/variable warning
}
// accept connections and process them, spawning a new tasks for each one
for stream in acceptor.incoming() {
spawn(proc() {
handle_client(stream);
});
match stream {
Err(e) => { /* connection failed */ }
Ok(stream) => spawn(proc() {
// connection succeeded
handle_client(stream)
})
}
}

// close the socket server
Expand Down
24 changes: 15 additions & 9 deletions src/libstd/io/net/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ impl Writer for TcpStream {
/// # Example
///
/// ```rust
/// # fn main() {}
/// # fn main() { }
/// # fn foo() {
/// # #[allow(unused_must_use, dead_code)];
/// use std::io::net::tcp::TcpListener;
/// # #![allow(dead_code)]
/// use std::io::{TcpListener, TcpStream};
/// use std::io::net::ip::{Ipv4Addr, SocketAddr};
/// use std::io::{Acceptor, Listener};
///
Expand All @@ -113,12 +113,19 @@ impl Writer for TcpStream {
/// // bind the listener to the specified address
/// let mut acceptor = listener.listen();
///
/// // accept connections and process them
/// # fn handle_client<T>(_: T) {}
/// fn handle_client(mut stream: TcpStream) {
/// // ...
/// # &mut stream; // silence unused mutability/variable warning
/// }
/// // accept connections and process them, spawning a new tasks for each one
/// for stream in acceptor.incoming() {
/// spawn(proc() {
/// handle_client(stream);
/// });
/// match stream {
/// Err(e) => { /* connection failed */ }
/// Ok(stream) => spawn(proc() {
/// // connection succeeded
/// handle_client(stream)
/// })
/// }
/// }
///
/// // close the socket server
Expand Down Expand Up @@ -728,4 +735,3 @@ mod test {
assert_eq!(s.read_to_end(), Ok(vec!(1)));
})
}

2 changes: 1 addition & 1 deletion src/libstd/sync/atomics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub struct AtomicOption<T> {
///
/// Rust's memory orderings are the same as in C++[1].
///
/// [1]: http://gcc.gnu.org/wiki/Atomic/GCCMM/AtomicSync
/// 1: http://gcc.gnu.org/wiki/Atomic/GCCMM/AtomicSync
pub enum Ordering {
/// No ordering constraints, only atomic operations
Relaxed,
Expand Down
4 changes: 1 addition & 3 deletions src/libstd/unstable/finally.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ also be used. See that function for more details.

```
use std::unstable::finally::Finally;
# fn always_run_this() {}

(|| {
// ...
}).finally(|| {
always_run_this();
// this code is always run
})
```
*/
Expand Down Expand Up @@ -158,4 +157,3 @@ fn test_compact() {
do_some_fallible_work.finally(
but_always_run_this_function);
}