Skip to content

TRPL: Add rust Marker to Some Code Block #25580

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

Merged
merged 2 commits into from
May 19, 2015
Merged
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
4 changes: 2 additions & 2 deletions src/doc/trpl/benchmark-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Rust supports benchmark tests, which can test the performance of your
code. Let's make our `src/lib.rs` look like this (comments elided):

```{rust,ignore}
```rust,ignore
#![feature(test)]

extern crate test;
Expand Down Expand Up @@ -77,7 +77,7 @@ the benchmark is no longer benchmarking what one expects. For example, the
compiler might recognize that some calculation has no external effects and
remove it entirely.

```{rust,ignore}
```rust,ignore
#![feature(test)]

extern crate test;
Expand Down
2 changes: 1 addition & 1 deletion src/doc/trpl/borrow-and-asref.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ kind of borrowed value. Slices are an area where this is especially true: you
can have both an `&[T]` or a `&mut [T]`. If we wanted to accept both of these
types, `Borrow` is up for it:

```
```rust
use std::borrow::Borrow;
use std::fmt::Display;

Expand Down
4 changes: 2 additions & 2 deletions src/doc/trpl/box-syntax-and-patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Also it is not possible in stable Rust to destructure a `Box` in a match
pattern. The unstable `box` keyword can be used to both create and destructure
a `Box`. An example usage would be:

```
```rust
#![feature(box_syntax, box_patterns)]

fn main() {
Expand Down Expand Up @@ -34,7 +34,7 @@ because the syntax may still change in the future.
In many languages with pointers, you'd return a pointer from a function
so as to avoid copying a large data structure. For example:

```{rust}
```rust
struct BigStruct {
one: i32,
two: i32,
Expand Down
12 changes: 6 additions & 6 deletions src/doc/trpl/concurrency.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ place!
Rust's standard library provides a library for threads, which allow you to
run Rust code in parallel. Here's a basic example of using `std::thread`:

```
```rust
use std::thread;

fn main() {
Expand All @@ -73,7 +73,7 @@ The `thread::spawn()` method accepts a closure, which is executed in a
new thread. It returns a handle to the thread, that can be used to
wait for the child thread to finish and extract its result:

```
```rust
use std::thread;

fn main() {
Expand Down Expand Up @@ -189,7 +189,7 @@ guard across thread boundaries, which gives us our error.

We can use `Arc<T>` to fix this. Here's the working version:

```
```rust
use std::sync::{Arc, Mutex};
use std::thread;

Expand Down Expand Up @@ -248,7 +248,7 @@ threads with each other. Let's talk about one of them: channels.
Here's a version of our code that uses channels for synchronization, rather
than waiting for a specific time:

```
```rust
use std::sync::{Arc, Mutex};
use std::thread;
use std::sync::mpsc;
Expand Down Expand Up @@ -281,7 +281,7 @@ a simple `()` down the channel, and then wait for ten of them to come back.
While this channel is just sending a generic signal, we can send any data that
is `Send` over the channel!

```
```rust
use std::thread;
use std::sync::mpsc;

Expand Down Expand Up @@ -311,7 +311,7 @@ the answer, and then it `send()`s us the answer over the channel.
A `panic!` will crash the currently executing thread. You can use Rust's
threads as a simple isolation mechanism:

```
```rust
use std::thread;

let result = thread::spawn(move || {
Expand Down
40 changes: 20 additions & 20 deletions src/doc/trpl/crates-and-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ above.
To define each of our modules, we use the `mod` keyword. Let’s make our
`src/lib.rs` look like this:

```
```rust
mod english {
mod greetings {
}
Expand Down Expand Up @@ -126,15 +126,15 @@ ways.

Instead of declaring a module like this:

```{rust,ignore}
```rust,ignore
mod english {
// contents of our module go here
}
```

We can instead declare our module like this:

```{rust,ignore}
```rust,ignore
mod english;
```

Expand Down Expand Up @@ -173,7 +173,7 @@ $ tree .

`src/lib.rs` is our crate root, and looks like this:

```{rust,ignore}
```rust,ignore
mod english;
mod japanese;
```
Expand All @@ -184,7 +184,7 @@ on our preference. In this case, because our modules have sub-modules, we’ve
chosen the second. Both `src/english/mod.rs` and `src/japanese/mod.rs` look
like this:

```{rust,ignore}
```rust,ignore
mod greetings;
mod farewells;
```
Expand Down Expand Up @@ -297,7 +297,7 @@ public, and so private is the default. To make things public, you use the `pub`
keyword. Let’s focus on the `english` module first, so let’s reduce our `src/main.rs`
to just this:

```{rust,ignore}
```rust,ignore
extern crate phrases;

fn main() {
Expand All @@ -308,29 +308,29 @@ fn main() {

In our `src/lib.rs`, let’s add `pub` to the `english` module declaration:

```{rust,ignore}
```rust,ignore
pub mod english;
mod japanese;
```

And in our `src/english/mod.rs`, let’s make both `pub`:

```{rust,ignore}
```rust,ignore
pub mod greetings;
pub mod farewells;
```

In our `src/english/greetings.rs`, let’s add `pub` to our `fn` declaration:

```{rust,ignore}
```rust,ignore
pub fn hello() -> String {
"Hello!".to_string()
}
```

And also in `src/english/farewells.rs`:

```{rust,ignore}
```rust,ignore
pub fn goodbye() -> String {
"Goodbye.".to_string()
}
Expand Down Expand Up @@ -365,7 +365,7 @@ refer to them with shorter names. Let’s talk about `use`.
Rust has a `use` keyword, which allows us to import names into our local scope.
Let’s change our `src/main.rs` to look like this:

```{rust,ignore}
```rust,ignore
extern crate phrases;

use phrases::english::greetings;
Expand All @@ -382,7 +382,7 @@ the functions by a much shorter name. By convention, when importing functions, i
considered best practice to import the module, rather than the function directly. In
other words, you _can_ do this:

```{rust,ignore}
```rust,ignore
extern crate phrases;

use phrases::english::greetings::hello;
Expand All @@ -400,7 +400,7 @@ becomes a problem. If we have conflicting names, Rust will give a compilation
error. For example, if we made the `japanese` functions public, and tried to do
this:

```{rust,ignore}
```rust,ignore
extern crate phrases;

use phrases::english::greetings::hello;
Expand All @@ -426,14 +426,14 @@ Could not compile `phrases`.
If we’re importing multiple names from the same module, we don’t have to type it out
twice. Instead of this:

```{rust,ignore}
```rust,ignore
use phrases::english::greetings;
use phrases::english::farewells;
```

We can use this shortcut:

```{rust,ignore}
```rust,ignore
use phrases::english::{greetings, farewells};
```

Expand All @@ -445,7 +445,7 @@ interface that may not directly map to your internal code organization.

Let’s look at an example. Modify your `src/main.rs` to read like this:

```{rust,ignore}
```rust,ignore
extern crate phrases;

use phrases::english::{greetings,farewells};
Expand All @@ -462,30 +462,30 @@ fn main() {

Then, modify your `src/lib.rs` to make the `japanese` mod public:

```{rust,ignore}
```rust,ignore
pub mod english;
pub mod japanese;
```

Next, make the two functions public, first in `src/japanese/greetings.rs`:

```{rust,ignore}
```rust,ignore
pub fn hello() -> String {
"こんにちは".to_string()
}
```

And then in `src/japanese/farewells.rs`:

```{rust,ignore}
```rust,ignore
pub fn goodbye() -> String {
"さようなら".to_string()
}
```

Finally, modify your `src/japanese/mod.rs` to read like this:

```{rust,ignore}
```rust,ignore
pub use self::greetings::hello;
pub use self::farewells::goodbye;

Expand Down
Loading