@@ -126,15 +126,15 @@ ways.
126126
127127Instead of declaring a module like this:
128128
129- ``` { rust,ignore}
129+ ``` rust,ignore
130130mod english {
131131 // contents of our module go here
132132}
133133```
134134
135135We can instead declare our module like this:
136136
137- ``` { rust,ignore}
137+ ``` rust,ignore
138138mod english;
139139```
140140
@@ -173,7 +173,7 @@ $ tree .
173173
174174` src/lib.rs ` is our crate root, and looks like this:
175175
176- ``` { rust,ignore}
176+ ``` rust,ignore
177177mod english;
178178mod japanese;
179179```
@@ -184,7 +184,7 @@ on our preference. In this case, because our modules have sub-modules, we’ve
184184chosen the second. Both ` src/english/mod.rs ` and ` src/japanese/mod.rs ` look
185185like this:
186186
187- ``` { rust,ignore}
187+ ``` rust,ignore
188188mod greetings;
189189mod farewells;
190190```
@@ -297,7 +297,7 @@ public, and so private is the default. To make things public, you use the `pub`
297297keyword. Let’s focus on the ` english` module first, so let’s reduce our ` src/main.rs`
298298to just this:
299299
300- ` ` ` { rust,ignore}
300+ ` ` ` rust,ignore
301301extern crate phrases;
302302
303303fn main () {
@@ -308,29 +308,29 @@ fn main() {
308308
309309In our ` src/lib.rs` , let’s add ` pub` to the ` english` module declaration:
310310
311- ` ` ` { rust,ignore}
311+ ` ` ` rust,ignore
312312pub mod english;
313313mod japanese;
314314` ` `
315315
316316And in our ` src/english/mod.rs` , let’s make both ` pub` :
317317
318- ` ` ` { rust,ignore}
318+ ` ` ` rust,ignore
319319pub mod greetings;
320320pub mod farewells;
321321` ` `
322322
323323In our ` src/english/greetings.rs` , let’s add ` pub` to our ` fn` declaration:
324324
325- ` ` ` { rust,ignore}
325+ ` ` ` rust,ignore
326326pub fn hello () -> String {
327327 " Hello!" .to_string()
328328}
329329` ` `
330330
331331And also in ` src/english/farewells.rs` :
332332
333- ` ` ` { rust,ignore}
333+ ` ` ` rust,ignore
334334pub fn goodbye () -> String {
335335 " Goodbye." .to_string()
336336}
@@ -365,7 +365,7 @@ refer to them with shorter names. Let’s talk about `use`.
365365Rust has a ` use` keyword, which allows us to import names into our local scope.
366366Let’s change our ` src/main.rs` to look like this:
367367
368- ` ` ` { rust,ignore}
368+ ` ` ` rust,ignore
369369extern crate phrases;
370370
371371use phrases::english::greetings;
@@ -382,7 +382,7 @@ the functions by a much shorter name. By convention, when importing functions, i
382382considered best practice to import the module, rather than the function directly. In
383383other words, you _can_ do this:
384384
385- ` ` ` { rust,ignore}
385+ ` ` ` rust,ignore
386386extern crate phrases;
387387
388388use phrases::english::greetings::hello;
@@ -400,7 +400,7 @@ becomes a problem. If we have conflicting names, Rust will give a compilation
400400error. For example, if we made the ` japanese` functions public, and tried to do
401401this:
402402
403- ` ` ` { rust,ignore}
403+ ` ` ` rust,ignore
404404extern crate phrases;
405405
406406use phrases::english::greetings::hello;
@@ -426,14 +426,14 @@ Could not compile `phrases`.
426426If we’re importing multiple names from the same module, we don’t have to type it out
427427twice. Instead of this:
428428
429- ` ` ` { rust,ignore}
429+ ` ` ` rust,ignore
430430use phrases::english::greetings;
431431use phrases::english::farewells;
432432` ` `
433433
434434We can use this shortcut:
435435
436- ` ` ` { rust,ignore}
436+ ` ` ` rust,ignore
437437use phrases::english::{greetings, farewells};
438438` ` `
439439
@@ -445,7 +445,7 @@ interface that may not directly map to your internal code organization.
445445
446446Let’s look at an example. Modify your ` src/main.rs` to read like this:
447447
448- ` ` ` { rust,ignore}
448+ ` ` ` rust,ignore
449449extern crate phrases;
450450
451451use phrases::english::{greetings,farewells};
@@ -462,30 +462,30 @@ fn main() {
462462
463463Then, modify your ` src/lib.rs` to make the ` japanese` mod public:
464464
465- ` ` ` { rust,ignore}
465+ ` ` ` rust,ignore
466466pub mod english;
467467pub mod japanese;
468468` ` `
469469
470470Next, make the two functions public, first in ` src/japanese/greetings.rs` :
471471
472- ` ` ` { rust,ignore}
472+ ` ` ` rust,ignore
473473pub fn hello () -> String {
474474 " こんにちは" .to_string()
475475}
476476` ` `
477477
478478And then in ` src/japanese/farewells.rs` :
479479
480- ` ` ` { rust,ignore}
480+ ` ` ` rust,ignore
481481pub fn goodbye () -> String {
482482 " さようなら" .to_string()
483483}
484484` ` `
485485
486486Finally, modify your ` src/japanese/mod.rs` to read like this:
487487
488- ` ` ` { rust,ignore}
488+ ` ` ` rust,ignore
489489pub use self::greetings::hello;
490490pub use self::farewells::goodbye;
491491
0 commit comments