Skip to content

Commit c106d16

Browse files
authored
Merge pull request #1329 from second-state/type-cast
Improve the conversion example
2 parents a663846 + cb328e7 commit c106d16

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/conversion.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# Conversion
22

3-
Rust addresses conversion between types by the use of [traits]. The generic
3+
Primitive types can be converted to each other through [casting].
4+
5+
Rust addresses conversion between custom types (i.e., `struct` and `enum`)
6+
by the use of [traits]. The generic
47
conversions will use the [`From`] and [`Into`] traits. However there are more
58
specific ones for the more common cases, in particular when converting to and
69
from `String`s.
710

11+
[casting]: types/cast.md
812
[traits]: trait.md
913
[`From`]: https://doc.rust-lang.org/std/convert/trait.From.html
1014
[`Into`]: https://doc.rust-lang.org/std/convert/trait.Into.html

src/types/cast.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ fn main() {
2222
let integer = decimal as u8;
2323
let character = integer as char;
2424
25+
// Error! There are limitations in conversion rules. A float cannot be directly converted to a char.
26+
let character = decimal as char;
27+
// FIXME ^ Comment out this line
28+
2529
println!("Casting: {} -> {} -> {}", decimal, integer, character);
2630
2731
// when casting any value to an unsigned type, T,

0 commit comments

Comments
 (0)