File tree 1 file changed +26
-2
lines changed
1 file changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -1463,9 +1463,33 @@ mod true_keyword {}
1463
1463
//
1464
1464
/// Define an alias for an existing type.
1465
1465
///
1466
- /// The documentation for this keyword is [not yet complete]. Pull requests welcome!
1466
+ /// The syntax is `type Name = ExistingType;`.
1467
1467
///
1468
- /// [not yet complete]: https://github.com/rust-lang/rust/issues/34601
1468
+ /// # Examples
1469
+ ///
1470
+ /// `type` does **not** create a new type:
1471
+ ///
1472
+ /// ```rust
1473
+ /// type Meters = u32;
1474
+ /// type Kilograms = u32;
1475
+ ///
1476
+ /// let m: Meters = 3;
1477
+ /// let k: Kilograms = 3;
1478
+ ///
1479
+ /// assert_eq!(m, k);
1480
+ /// ```
1481
+ ///
1482
+ /// In traits, using `type` allows the usage of an associated type without
1483
+ /// knowing about it when declaring the [`trait`]:
1484
+ ///
1485
+ /// ```rust
1486
+ /// trait Iterator {
1487
+ /// type Item;
1488
+ /// fn next(&mut self) -> Option<Self::Item>;
1489
+ /// }
1490
+ /// ```
1491
+ ///
1492
+ /// [`trait`]: keyword.trait.html
1469
1493
mod type_keyword { }
1470
1494
1471
1495
#[ doc( keyword = "unsafe" ) ]
You can’t perform that action at this time.
0 commit comments