diff --git a/src/conversion.md b/src/conversion.md index 78d9e2d31e..52a96d06c4 100644 --- a/src/conversion.md +++ b/src/conversion.md @@ -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 diff --git a/src/types/cast.md b/src/types/cast.md index 350f9d6fe6..7d990976a3 100644 --- a/src/types/cast.md +++ b/src/types/cast.md @@ -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,