6 ms·
This isn't quite the same, because it's just an alias - you can pass a UserID to a function accepting a PostID: https://play.golang.org/p/nSOgcJs_66y https://pl
by njs12345 6y ago
This isn't quite the same, because it's just an alias - you can pass a UserID to a function accepting a PostID: https://play.golang.org/p/nSOgcJs_66y https://play.golang.org/p/nSOgcJs_66y
It still provides a documentation benefit of course.
EDIT: Whoops, yes, as lentil points out, they are indeed distinct types not aliases. So it does provide the benefit of the Rust solution.
- lentil 6y agoNo, it's not an alias, they are distinct types. You can't use the types interchangeably (unless you cast them). Your playground example didn't try to pass a UserID to a function accepting a PostID, but if you do that, you'll see the error: https://play.golang.org/p/vyiJ_sLzy4O https://play.golang.org/p/vyiJ_sLzy4O