File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -234,6 +234,22 @@ It allows a type to make certain promises about its behavior.
234
234
235
235
Generic functions and generic structs can use traits to constrain, or bound, the types they accept.
236
236
237
+ ### Turbofish
238
+
239
+ Paths with generic parameters in expressions must prefix the opening brackets with a ` :: ` .
240
+ Combined with the angular brackets for generics, this looks like a fish ` ::<> ` .
241
+ As such, this syntax is colloquially referred to as turbofish syntax.
242
+
243
+ Examples:
244
+
245
+ ``` rust
246
+ let ok_num = Ok :: <_ , ()>(5 );
247
+ let vec = [1 , 2 , 3 ]. iter (). map (| n | n * 2 ). collect :: <Vec <_ >>();
248
+ ```
249
+
250
+ This ` :: ` prefix is required to disambiguate generic paths with multiple comparisons in a comma-separate list.
251
+ See [ the bastion of the turbofish] [ turbofish test ] for an example.
252
+
237
253
### Uncovered type
238
254
239
255
A type which does not appear as an argument to another type. For example,
@@ -286,6 +302,7 @@ example of an uninhabited type is the [never type] `!`, or an enum with no varia
286
302
[ structs ] : items/structs.md
287
303
[ trait objects ] : types/trait-object.md
288
304
[ traits ] : items/traits.md
305
+ [ turbofish test ] : https://github.com/rust-lang/rust/blob/master/src/test/ui/bastion-of-the-turbofish.rs
289
306
[ types ] : types.md
290
307
[ undefined-behavior ] : behavior-considered-undefined.md
291
308
[ unions ] : items/unions.md
You can’t perform that action at this time.
0 commit comments