Skip to content

Commit

Permalink
Merge pull request #1329 from second-state/type-cast
Browse files Browse the repository at this point in the history
Improve the conversion example
  • Loading branch information
marioidival authored Apr 9, 2020
2 parents a663846 + cb328e7 commit c106d16
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/conversion.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Conversion

Rust addresses conversion between types by the use of [traits]. The generic
Primitive types can be converted to each other through [casting].

Rust addresses conversion between custom types (i.e., `struct` and `enum`)
by the use of [traits]. The generic
conversions will use the [`From`] and [`Into`] traits. However there are more
specific ones for the more common cases, in particular when converting to and
from `String`s.

[casting]: types/cast.md
[traits]: trait.md
[`From`]: https://doc.rust-lang.org/std/convert/trait.From.html
[`Into`]: https://doc.rust-lang.org/std/convert/trait.Into.html
4 changes: 4 additions & 0 deletions src/types/cast.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ fn main() {
let integer = decimal as u8;
let character = integer as char;
// Error! There are limitations in conversion rules. A float cannot be directly converted to a char.
let character = decimal as char;
// FIXME ^ Comment out this line
println!("Casting: {} -> {} -> {}", decimal, integer, character);
// when casting any value to an unsigned type, T,
Expand Down

0 comments on commit c106d16

Please sign in to comment.