google / comprehensive-rust

This is the Rust course used by the Android team at Google. It provides you the material to quickly teach Rust.
https://google.github.io/comprehensive-rust/
Apache License 2.0
27.47k stars 1.63k forks source link

"Type Aliases" improvements #1515

Open djmitche opened 9 months ago

djmitche commented 9 months ago

From my notes:

@deavid I've lost the context for this comment. Now that v2 has landed, do you remember enough to make a PR for this?

deavid commented 9 months ago

https://google.github.io/comprehensive-rust/user-defined-types/aliases.html

The problem is that the only usage is: RwLock<Vec<Arc<RefCell<Item>>>>

And it is hard to spot "Item" in there.

This is one of these instances where a mentor can explain things better but anyone trying to follow it on their own will be puzzled.

Adding a function where we can see the usefulness would be interesting, for example:

fn inventory_into_vec(inv: PlayerInventory) -> Vec<Item> {
   // ...
}

Just an example. Could be simpler. But having a practical use where we can showcase the usefulness would be interesting. Although to be fair we don't use type aliases often, or at least I don't.