Skip to content

Commit b7f6d7d

Browse files
authored
Merge pull request rust-lang#23 from killercup/patch-2
Fix some typos in tutorial
2 parents 5eb9a3a + 2fabc33 commit b7f6d7d

File tree

1 file changed

+48
-47
lines changed

1 file changed

+48
-47
lines changed

TUTORIAL.md

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ method to actually perform the TLS handshake. The first argument is the domain
188188
name we think we're connecting to, with the I/O object as the second.
189189

190190
[`ClientContext::new`]: http://alexcrichton.com/futures-rs/futures_tls/struct.ClientContext.html#method.new
191-
[handshake]: http://alexcrichton.com/futures-rs/futures_tls/struct.ClientContext.html#method.handshake
191+
[`handshake`]: http://alexcrichton.com/futures-rs/futures_tls/struct.ClientContext.html#method.handshake
192192

193193
Like with the [`tcp_connect`] from before, however, the [`handshake`] method
194194
returns a future. The actual TLS handshake may take some time as the client and
@@ -341,12 +341,12 @@ bounds can be found in the [FAQ][faq-why-send].
341341

342342
[Back to `Future`][future-trait]
343343

344-
```
344+
```rust
345345
type Item: Send + 'static;
346346
type Error: Send + 'static;
347347
```
348348

349-
The next property of the [`Future`] trait you'll probably notice are the two
349+
The next property of the [`Future`] trait you'll probably notice is the two
350350
associated types it contains. These represent the types of values that the
351351
`Future` can resolve to. Each instance of `Future` can be thought of as
352352
resolving to a `Result<Self::Item, Self::Error>`.
@@ -380,7 +380,7 @@ fn foo<F>(future: F)
380380

381381
[Back to `Future`][future-trait]
382382

383-
```
383+
```rust
384384
fn poll(&mut self, task: &mut Task) -> Poll<Self::Item, Self::Error>;
385385
fn schedule(&mut self, task: &mut Task);
386386
```
@@ -435,11 +435,11 @@ panic, some may never resolve again, etc. This means that implementors of the
435435
[`Future`] trait don't need to maintain state to check if [`poll`] has already
436436
returned successfully.
437437

438-
If a call to [`poll`] return `Poll::NotReady`, then futures still need to know
438+
If a call to [`poll`] returns `Poll::NotReady`, then futures still need to know
439439
how to figure out when to get poll'd later! This is where the [`schedule`]
440-
method comes into the picture. Like with [`poll`] this method takes `&mut self`,
440+
method comes into the picture. Like with [`poll`], this method takes `&mut self`,
441441
giving us the same guarantees as before. Similarly, it is passed a [`Task`], but
442-
the relationship between [`schedule`] and [`Task`] is somewhat different that
442+
the relationship between [`schedule`] and [`Task`] is somewhat different than
443443
that `poll` has.
444444

445445
Each [`Task`] can have a [`TaskHandle`] extracted from it via the
@@ -472,9 +472,9 @@ you want to convert it to a future of `u32`? For this sort of composition, the
472472
`Future` trait also provides a large number of **combinators** which can be seen
473473
on the [`Future`] trait itself.
474474

475-
The combinators are designed to be very similar to the `Iterator` combinators.
476-
That is, they all consume the receiving future and return a new future. For
477-
example we could have:
475+
These combinators are designed to be very similar to the [`Iterator`]
476+
combinators. That is, they all consume the receiving future and return a new
477+
future. For example, we could have:
478478

479479
```rust
480480
fn parse<F>(future: F) -> Box<Future<Item=u32, Error=F::Error>>
@@ -487,18 +487,20 @@ fn parse<F>(future: F) -> Box<Future<Item=u32, Error=F::Error>>
487487
```
488488

489489
Here we're using [`map`] to transform a future of `String` to a future of `u32`,
490-
ignoring errors. This example returns a `Box`, but that's not always necessary,
490+
ignoring errors. This example returns a [`Box`], but that's not always necessary,
491491
and is discussed in the [returning futures][returning-futures] section.
492492

493493
The combinators on futures allow expressing concepts like:
494494

495-
* Change the type of a future ([`map`], [`map_err]`)
495+
* Change the type of a future ([`map`], [`map_err`])
496496
* Run another future after one has completed ([`then`], [`and_then`],
497497
[`or_else`])
498498
* Figuring out which of two futures resolves first ([`select`])
499499
* Waiting for two futures to both complete ([`join`])
500500
* Defining the behavior of [`poll`] after resolution ([`fuse`])
501501

502+
[`Iterator`]: https://doc.rust-lang.org/1.10.0/std/iter/trait.Iterator.html
503+
[`Box`]: https://doc.rust-lang.org/1.10.0/std/boxed/struct.Box.html
502504
[`map`]: http://alexcrichton.com/futures-rs/futures/trait.Future.html#method.map
503505
[`map_err`]: http://alexcrichton.com/futures-rs/futures/trait.Future.html#method.map_err
504506
[`then`]: http://alexcrichton.com/futures-rs/futures/trait.Future.html#method.then
@@ -508,11 +510,11 @@ The combinators on futures allow expressing concepts like:
508510
[`join`]: http://alexcrichton.com/futures-rs/futures/trait.Future.html#method.join
509511
[`fuse`]: http://alexcrichton.com/futures-rs/futures/trait.Future.html#method.fuse
510512

511-
Usage of the combinators should feel very similar to the `Iterator` trait in
512-
Rust or futures in [Scala][scala-futures]. Most composition of futures ends up
513-
being done through these combinators. All combinators are zero-cost which is
514-
another way of saying no memory is allocated internally and the implementation
515-
will optimize to what you would have otherwise written by hand.
513+
Usage of the combinators should feel very similar to the [`Iterator`] trait in
514+
Rust or [futures in Scala][scala-futures]. Most composition of futures ends up
515+
being done through these combinators. All combinators are zero-cost, that means
516+
no memory is allocated internally and the implementation will optimize to what
517+
you would have otherwise written by hand.
516518

517519
---
518520

@@ -521,10 +523,10 @@ will optimize to what you would have otherwise written by hand.
521523

522524
[Back to top][top]
523525

524-
Previously we've taken a long look at the [`Future`] trait which is useful if
525-
we're only producing one value over time, but sometimes computations are best
526-
modeled as a *stream* of values being produced over time. For example a TCP
527-
listener produces a number of TCP socket connections over its lifetime. For
526+
Previously, we've taken a long look at the [`Future`] trait which is useful if
527+
we're only producing one value over time. But sometimes computations are best
528+
modeled as a *stream* of values being produced over time. For example, a TCP
529+
listener produces a number of TCP socket connections over its lifetime. For
528530
that purpose the [`futures`] crate also includes a [`Stream`] trait:
529531

530532
```rust
@@ -547,7 +549,7 @@ stream's [`poll`][stream-poll] method return `Option<Self::Item>` instead of
547549

548550
A [`Stream`] produces optionally many values over time, signaling termination of
549551
the stream by returning `Poll::Ok(None)`. At its heart a [`Stream`] represents
550-
and asynchronous stream of values being produced in order.
552+
an asynchronous stream of values being produced in order.
551553

552554
A [`Stream`] is actually just a special instance of a [`Future`], and can be
553555
converted to a future through the [`into_future`] method. The [returned
@@ -572,31 +574,30 @@ stream-specific combinators like [`fold`] are also provided.
572574

573575
[Back to top][top]
574576

575-
Alright at this point we've got a good idea of the [`Future`] and [`Stream`]
577+
Alright! At this point we've got a good idea of the [`Future`] and [`Stream`]
576578
traits both in how they're implemented as well as how they're composed together.
577-
But where to all these futures originally come from? Let's take a look at a few
579+
But where do all these futures originally come from? Let's take a look at a few
578580
concrete implementations of futures and streams here.
579581

580582
First, any value already available is trivially a future that is immediately
581-
ready. For this, the [`done`], [`failed`], [`finished`] suffice. The [`done`]
582-
variant takes a `Result<T, E>` and returns a `Future<Item=T, Error=E>`. The
583-
[`failed`] and [`finished`] variants then specify either `T` or `E` and leave
584-
the other associated type as a wildcard.
583+
ready. For this, the [`done`], [`failed`], [`finished`] functions suffice. The
584+
[`done`] variant takes a `Result<T, E>` and returns a `Future<Item=T, Error=E>`.
585+
The [`failed`] and [`finished`] variants then specify either `T` or `E` and
586+
leave the other associated type as a wildcard.
585587

586588
[`done`]: http://alexcrichton.com/futures-rs/futures/fn.done.html
587589
[`finished`]: http://alexcrichton.com/futures-rs/futures/fn.finished.html
588590
[`failed`]: http://alexcrichton.com/futures-rs/futures/fn.failed.html
589591

590-
For streams the equivalent of an "immediately ready" stream is the [`iter`]
592+
For streams, the equivalent of an "immediately ready" stream is the [`iter`]
591593
function which creates a stream that yields the same items as the underlying
592594
iterator.
593595

594596
[`iter`]: http://alexcrichton.com/futures-rs/futures/stream/fn.iter.html
595597

596598
In situations though where a value isn't immediately ready, there are also much
597599
more general implementations of [`Future`] and [`Stream`] that are available in
598-
the [`futures`] crate, the first of which is [`promise`]. Let's first take a
599-
look:
600+
the [`futures`] crate, the first of which is [`promise`]. Let's take a look:
600601

601602
[`promise`]: http://alexcrichton.com/futures-rs/futures/fn.promise.html
602603

@@ -623,14 +624,15 @@ fn main() {
623624
```
624625

625626
Here we can see that the [`promise`] function returns two halves (like
626-
[`mspc::channel`]). The first half, `tx`, is of type [`Complete`] and is used to
627-
complete the promise, providing a value to the future on the other end. The
628-
[`Complete::complete`] method will transmit the value to the receiving end.
627+
[`mpsc::channel`]). The first half, `tx` ("transmitter"), is of type [`Complete`]
628+
and is used to complete the promise, providing a value to the future on the
629+
other end. The [`Complete::complete`] method will transmit the value to the
630+
receiving end.
629631

630-
The second half, `rx`, is of type [`Promise`] which is a type that implements
631-
the [`Future`] trait. The `Item` type is `T`, the type of the promise. The
632-
`Error` type is [`Canceled`] which happens when the [`Complete`] half is dropped
633-
without completing the computation.
632+
The second half, `rx` ("receiver"), is of type [`Promise`] which is a type that
633+
implements the [`Future`] trait. The `Item` type is `T`, the type of the promise.
634+
The `Error` type is [`Canceled`], which happens when the [`Complete`] half is
635+
dropped without completing the computation.
634636

635637
[`mpsc::channel`]: https://doc.rust-lang.org/std/sync/mpsc/fn.channel.html
636638
[`Complete`]: http://alexcrichton.com/futures-rs/futures/struct.Complete.html
@@ -641,9 +643,8 @@ without completing the computation.
641643
This concrete implementation of `Future` can be used (as shown here) to
642644
communicate values across threads. Each half implements the `Send` trait and is
643645
a separately owned entity to get passed around. It's generally not recommended
644-
to make liberal use of this type of future, however, unless necessary. The
645-
combinators above or other forms of base futures should be preferred wherever
646-
possible.
646+
to make liberal use of this type of future, however. The combinators above or
647+
other forms of base futures should be preferred wherever possible.
647648

648649
For the [`Stream`] trait, a similar primitive is available, [`channel`]. This
649650
type also has two halves, where the sending half is used to send messages and
@@ -665,8 +666,8 @@ has caught up.
665666

666667
[Back to top][top]
667668

668-
When working with futures one of the first things you're likely to run into is
669-
wanting to return a [`Future`]! Like with the `Iterator` trait, however, this
669+
When working with futures, one of the first things you're likely to run into is
670+
wanting to return a [`Future`]! Like with the [`Iterator`] trait, however, this
670671
isn't currently always the easiest thing to do. Let's walk through your options,
671672
however.
672673

@@ -688,7 +689,7 @@ fn foo() -> Box<Future<Item = u32, Error = io::Error>> {
688689
}
689690
```
690691

691-
The upside of this strategy is that it's easy to write down (just a `Box`) and
692+
The upside of this strategy is that it's easy to write down (just a [`Box`]) and
692693
easy to create (through the [`boxed`] method). This is also maximally flexible
693694
in terms of future changes to the method as *any* future can be returned from
694695
this method.
@@ -827,13 +828,13 @@ Enter, a [`Task`]!
827828
In the [`futures`] crate there is a struct called [`Task`] which is used to
828829
drive a computation represented by futures. One particular instance of a
829830
`Future` may be short-lived, and may only be part of one large computations. For
830-
example in our ["hello world"][hello-world] example we had a number of futures,
831+
example, in our ["hello world"][hello-world] example we had a number of futures,
831832
but only one actually existed in memory at a time. For the entire program, we'll
832833
have one [`Task`] that followed the logical "thread of execution" as the future
833834
progressed.
834835

835836
In short, a `Task` is the one that's actually orchestrating the top-level calls
836-
to `poll` and `schedule`. Its main method, [`run`] does exactly this. Internally
837+
to `poll` and `schedule`. Its main method, [`run`] does exactly this. Internally,
837838
`Task` has synchronization for if [`notify`] is called on multiple threads it'll
838839
ensure that the calls to [`poll`] are coordinated.
839840

@@ -856,7 +857,7 @@ lifetime of the computation.
856857

857858
---
858859

859-
## Task local data
860+
## Task-local data
860861
[task-local-data]: #task-local-data
861862

862863
[Back to top][top]

0 commit comments

Comments
 (0)