File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
+ #[ doc( keyword = "as" ) ]
12
+ //
13
+ /// The type coercion keyword
14
+ ///
15
+ /// `as` is most commonly used to turn primitive types into other primitive types, but it has other
16
+ /// uses that include turning pointers into addresses, addresses into pointers, and pointers into
17
+ /// other pointers.
18
+ ///
19
+ /// ```rust
20
+ /// let thing1: u8 = 89.0 as u8;
21
+ /// assert_eq!('B' as u32, 66);
22
+ /// assert_eq!(thing1 as char, 'Y');
23
+ /// let thing2: f32 = thing1 as f32 + 10.5;
24
+ /// assert_eq!(true as u8 + thing2 as u8, 100);
25
+ /// ```
26
+ ///
27
+ /// In general, any coercion that can be performed via writing out type hints can also be done
28
+ /// using `as`, so instead of writing `let x: u32 = 123`, you can write `let x = 123 as u32` (Note:
29
+ /// `let x = 123u32` would be best in that situation). The same is not true in the other direction,
30
+ /// however, explicitly using `as` allows a few more coercions that aren't allowed implicitly, such
31
+ /// as changing the type of a raw pointer or turning closures into raw pointers.
32
+ ///
33
+ /// For more information on what `as` is capable of, see the [Reference]
34
+ ///
35
+ /// [Reference]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions
36
+ mod as_keyword { }
37
+
11
38
#[ doc( keyword = "fn" ) ]
12
39
//
13
40
/// The `fn` keyword.
You can’t perform that action at this time.
0 commit comments