Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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