google / comprehensive-rust

This is the Rust course used by the Android team at Google. It provides you the material to quickly teach Rust.

Home Page:https://google.github.io/comprehensive-rust/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`From` and `Into` slide should emphasize losslessness and infallibility

fw-immunant opened this issue · comments

The standard library docs mention this:

The From trait is intended for perfect conversions. If the conversion can fail or is not perfect, use TryFrom.

But it's easy to miss one line in the docs; I think we should emphasize this in the speaker notes. It also isn't necessarily obvious what "perfect" means, so I think "lossless" is a better way to describe the contract of these traits. This is worth underlining because the commonsense notion of being able to convert between types may also apply to things like C-style casts that truncate and are not appropriate for these traits.