Skip to content

Commit d2f265d

Browse files
committed
auto merge of #12367 : darnuria/rust/tutorial_removing_do_syntax, r=cmr
The 'do' keyword was deprecated in 0.10 #11868 , and is keep as reserved keyword #12157 . So the tutorial part about it doesn't make sense. The spawning explanation was move into '15.2 Closure compatibility'.
2 parents c4afcf4 + 1ede49f commit d2f265d

File tree

1 file changed

+18
-39
lines changed

1 file changed

+18
-39
lines changed

src/doc/tutorial.md

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,6 +1750,24 @@ closures, but they also own them: that is, no other code can access
17501750
them. Owned closures are used in concurrent code, particularly
17511751
for spawning [tasks][tasks].
17521752
1753+
Closures can be used to spawn tasks.
1754+
A practical example of this pattern is found when using the `spawn` function,
1755+
which starts a new task.
1756+
1757+
~~~~
1758+
use std::task::spawn;
1759+
1760+
// proc is the closure which will be spawned.
1761+
spawn(proc() {
1762+
debug!("I'm a new task")
1763+
});
1764+
~~~~
1765+
1766+
> ***Note:*** If you want to see the output of `debug!` statements, you will need to turn on
1767+
> `debug!` logging. To enable `debug!` logging, set the RUST_LOG environment
1768+
> variable to the name of your crate, which, for a file named `foo.rs`, will be
1769+
> `foo` (e.g., with bash, `export RUST_LOG=foo`).
1770+
17531771
## Closure compatibility
17541772
17551773
Rust closures have a convenient subtyping property: you can pass any kind of
@@ -1771,45 +1789,6 @@ call_twice(function);
17711789
> in small ways. At the moment they can be unsound in some
17721790
> scenarios, particularly with non-copyable types.
17731791
1774-
## Do syntax
1775-
1776-
The `do` expression makes it easier to call functions that take procedures
1777-
as arguments.
1778-
1779-
Consider this function that takes a procedure:
1780-
1781-
~~~~
1782-
fn call_it(op: proc(v: int)) {
1783-
op(10)
1784-
}
1785-
~~~~
1786-
1787-
As a caller, if we use a closure to provide the final operator
1788-
argument, we can write it in a way that has a pleasant, block-like
1789-
structure.
1790-
1791-
~~~~
1792-
# fn call_it(op: proc(v: int)) { }
1793-
call_it(proc(n) {
1794-
println!("{}", n);
1795-
});
1796-
~~~~
1797-
1798-
A practical example of this pattern is found when using the `spawn` function,
1799-
which starts a new task.
1800-
1801-
~~~~
1802-
use std::task::spawn;
1803-
spawn(proc() {
1804-
debug!("I'm a new task")
1805-
});
1806-
~~~~
1807-
1808-
If you want to see the output of `debug!` statements, you will need to turn on
1809-
`debug!` logging. To enable `debug!` logging, set the RUST_LOG environment
1810-
variable to the name of your crate, which, for a file named `foo.rs`, will be
1811-
`foo` (e.g., with bash, `export RUST_LOG=foo`).
1812-
18131792
# Methods
18141793
18151794
Methods are like functions except that they always begin with a special argument,

0 commit comments

Comments
 (0)