Skip to content

Commit

Permalink
Removing '15.3 Do syntax' in tutorial.
Browse files Browse the repository at this point in the history
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'.

Fixing misspelling.

Thanks for precisions.

Moved from 15.2 to 15.1.

Fixed typo, and apply pnkfelix advices.
  • Loading branch information
darnuria committed Feb 18, 2014
1 parent b0ce960 commit 1ede49f
Showing 1 changed file with 18 additions and 39 deletions.
57 changes: 18 additions & 39 deletions src/doc/tutorial.md
Expand Up @@ -1750,6 +1750,24 @@ closures, but they also own them: that is, no other code can access
them. Owned closures are used in concurrent code, particularly
for spawning [tasks][tasks].

Closures can be used to spawn tasks.
A practical example of this pattern is found when using the `spawn` function,
which starts a new task.

~~~~
use std::task::spawn;
// proc is the closure which will be spawned.
spawn(proc() {
debug!("I'm a new task")
});
~~~~

> ***Note:*** If you want to see the output of `debug!` statements, you will need to turn on
> `debug!` logging. To enable `debug!` logging, set the RUST_LOG environment
> variable to the name of your crate, which, for a file named `foo.rs`, will be
> `foo` (e.g., with bash, `export RUST_LOG=foo`).
## Closure compatibility

Rust closures have a convenient subtyping property: you can pass any kind of
Expand All @@ -1771,45 +1789,6 @@ call_twice(function);
> in small ways. At the moment they can be unsound in some
> scenarios, particularly with non-copyable types.
## Do syntax

The `do` expression makes it easier to call functions that take procedures
as arguments.

Consider this function that takes a procedure:

~~~~
fn call_it(op: proc(v: int)) {
op(10)
}
~~~~

As a caller, if we use a closure to provide the final operator
argument, we can write it in a way that has a pleasant, block-like
structure.

~~~~
# fn call_it(op: proc(v: int)) { }
call_it(proc(n) {
println!("{}", n);
});
~~~~

A practical example of this pattern is found when using the `spawn` function,
which starts a new task.

~~~~
use std::task::spawn;
spawn(proc() {
debug!("I'm a new task")
});
~~~~

If you want to see the output of `debug!` statements, you will need to turn on
`debug!` logging. To enable `debug!` logging, set the RUST_LOG environment
variable to the name of your crate, which, for a file named `foo.rs`, will be
`foo` (e.g., with bash, `export RUST_LOG=foo`).

# Methods

Methods are like functions except that they always begin with a special argument,
Expand Down

5 comments on commit 1ede49f

@bors
Copy link
Contributor

@bors bors commented on 1ede49f Feb 19, 2014

Choose a reason for hiding this comment

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

saw approval from cmr
at darnuria@1ede49f

@bors
Copy link
Contributor

@bors bors commented on 1ede49f Feb 19, 2014

Choose a reason for hiding this comment

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

merging darnuria/rust/tutorial_removing_do_syntax = 1ede49f into auto

@bors
Copy link
Contributor

@bors bors commented on 1ede49f Feb 19, 2014

Choose a reason for hiding this comment

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

darnuria/rust/tutorial_removing_do_syntax = 1ede49f merged ok, testing candidate = d2f265d

@bors
Copy link
Contributor

@bors bors commented on 1ede49f Feb 19, 2014

Choose a reason for hiding this comment

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

@bors
Copy link
Contributor

@bors bors commented on 1ede49f Feb 19, 2014

Choose a reason for hiding this comment

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

fast-forwarding master to auto = d2f265d

Please sign in to comment.