]> git.proxmox.com Git - rustc.git/blobdiff - src/doc/book/src/ch19-05-advanced-functions-and-closures.md
New upstream version 1.34.2+dfsg1
[rustc.git] / src / doc / book / src / ch19-05-advanced-functions-and-closures.md
index 9fee7f21f4076d7eca241dda7ebd9499200746b8..b76d442d8bfea3c44df9e1e224ddbe70ea781966 100644 (file)
@@ -78,17 +78,18 @@ let list_of_strings: Vec<String> = list_of_numbers
 ```
 
 Note that we must use the fully qualified syntax that we talked about earlier
-in the “Advanced Traits” section because there are multiple functions available
-named `to_string`. Here, we’re using the `to_string` function defined in the
-`ToString` trait, which the standard library has implemented for any type that
-implements `Display`.
+in the [“Advanced Traits”][advanced-traits]<!-- ignore --> section because
+there are multiple functions available named `to_string`. Here, we’re using the
+`to_string` function defined in the `ToString` trait, which the standard
+library has implemented for any type that implements `Display`.
 
 Another useful pattern exploits an implementation detail of tuple structs and
-tuple-struct enum variants. These items use `()` as initialiser syntax, which
-looks like a function call, and they’re actually implemented as functions
-returning an instance constructed from their arguments. They can also be called
-as a function pointer implementing the closure traits, and so can be used
-similarly to the above:
+tuple-struct enum variants. These items use `()` as initializer syntax, which
+looks like a function call. The initializers are actually implemented as
+functions returning an instance constructed from their arguments. These
+initializer functions can also be used as a function pointer that implements
+the closure traits, so they can also be specified as arguments for methods that
+take closures:
 
 ```rust
 enum Status {
@@ -102,6 +103,8 @@ let list_of_statuses: Vec<Status> =
     .collect();
 ```
 
+This code creates `Status::Value` instances using each `u32` value in the range
+that `map` is called on by using the initializer function of `Status::Value`.
 Some people prefer this style, and some people prefer to use closures. They end
 up compiling to the same code, so use whichever style is clearer to you.
 
@@ -149,7 +152,13 @@ fn returns_closure() -> Box<dyn Fn(i32) -> i32> {
 ```
 
 This code will compile just fine. For more about trait objects, refer to the
-“Using Trait Objects That Allow for Values of Different Types” section in
-Chapter 17.
+[“Using Trait Objects That Allow for Values of Different Types”]
+[using-trait-objects-that-allow-for-values-of-different-types]<!-- ignore -->
+section in Chapter 17.
 
 Next, let’s look at macros!
+
+[advanced-traits]:
+ch19-03-advanced-traits.html#advanced-traits
+[using-trait-objects-that-allow-for-values-of-different-types]:
+ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types