@@ -41,7 +41,7 @@ concurrency: particularly, ownership. The language leaves the implementation
41
41
details to the standard library.
42
42
43
43
The ` spawn ` function has a very simple type signature: `fn spawn(f: proc():
44
- Send)`. Because it accepts only procs, and procs contain only owned data,
44
+ Send)`. Because it accepts only procs, and procs contain only owned data,
45
45
` spawn ` can safely move the entire proc and all its associated state into an
46
46
entirely different task for execution. Like any closure, the function passed to
47
47
` spawn ` may capture an environment that it carries across tasks.
@@ -213,7 +213,7 @@ println!("fib(50) = {}", delayed_fib.get())
213
213
# }
214
214
```
215
215
216
- The call to ` future::spawn ` returns immediately a ` future ` object regardless of
216
+ The call to ` future::spawn ` immediately returns a ` future ` object regardless of
217
217
how long it takes to run ` fib(50) ` . You can then make yourself a sandwich while
218
218
the computation of ` fib ` is running. The result of the execution of the method
219
219
is obtained by calling ` get ` on the future. This call will block until the
@@ -297,7 +297,7 @@ let numbers_arc = Arc::new(numbers);
297
297
```
298
298
299
299
and a clone is captured for each task via a procedure. This only copies
300
- the wrapper and not it's contents. Within the task's procedure, the captured
300
+ the wrapper and not its contents. Within the task's procedure, the captured
301
301
Arc reference can be used as a shared reference to the underlying vector as
302
302
if it were local.
303
303
@@ -323,20 +323,20 @@ Rust has a built-in mechanism for raising exceptions. The `fail!()` macro
323
323
(which can also be written with an error string as an argument: `fail!(
324
324
~ reason)` ) and the ` assert!` construct (which effectively calls ` fail!()` if a
325
325
boolean expression is false) are both ways to raise exceptions. When a task
326
- raises an exception the task unwinds its stack--- running destructors and
327
- freeing memory along the way--- and then exits. Unlike exceptions in C++,
326
+ raises an exception, the task unwinds its stack— running destructors and
327
+ freeing memory along the way— and then exits. Unlike exceptions in C++,
328
328
exceptions in Rust are unrecoverable within a single task: once a task fails,
329
329
there is no way to "catch" the exception.
330
330
331
331
While it isn't possible for a task to recover from failure, tasks may notify
332
332
each other of failure. The simplest way of handling task failure is with the
333
- ` try ` function, which is similar to ` spawn ` , but immediately blocks waiting for
334
- the child task to finish. ` try ` returns a value of type `Result<T, Box<Any +
335
- Send>>` . ` Result` is an ` enum` type with two variants: ` Ok ` and ` Err`. In this
336
- case, because the type arguments to ` Result ` are ` int ` and ` () ` , callers can
337
- pattern-match on a result to check whether it's an ` Ok ` result with an ` int `
338
- field (representing a successful result) or an ` Err ` result (representing
339
- termination with an error).
333
+ ` try ` function, which is similar to ` spawn ` , but immediately blocks and waits
334
+ for the child task to finish. ` try ` returns a value of type
335
+ ` Result<T, Box<Any + Send>>` . ` Result ` is an ` enum ` type with two variants:
336
+ ` Ok ` and ` Err ` . In this case, because the type arguments to ` Result ` are ` int `
337
+ and ` () ` , callers can pattern-match on a result to check whether it's an ` Ok `
338
+ result with an ` int ` field (representing a successful result) or an ` Err ` result
339
+ (representing termination with an error).
340
340
341
341
``` {rust}
342
342
# use std::task;
@@ -369,4 +369,4 @@ the entire program (perhaps you're writing an assert which, if it trips,
369
369
indicates an unrecoverable logic error); in other cases you might want to
370
370
contain the failure at a certain boundary (perhaps a small piece of input from
371
371
the outside world, which you happen to be processing in parallel, is malformed
372
- and its processing task can't proceed).
372
+ such that the processing task cannot proceed).
0 commit comments