comprehensive-rust icon indicating copy to clipboard operation
comprehensive-rust copied to clipboard

"Type Aliases" improvements

Open djmitche opened this issue 2 years ago • 1 comments

From my notes:

  • "9.5. Type Aliases: The example shows how to declare, but on how it looks in practice is not clear enough (there is a use of one type alias but it's hidden in a complex type). Ideally I would add some function signatures or custom structs that showcase the cleanliness of this." (@deavid)

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

djmitche avatar Nov 29 '23 16:11 djmitche

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.

deavid avatar Dec 13 '23 20:12 deavid