7 ms·
If you need api flexibility you use generics, and that is the way to be generic over types that refer to strs. I'm pretty sure this is in the book, and it's com
by hctaw 6y ago
If you need api flexibility you use generics, and that is the way to be generic over types that refer to strs. I'm pretty sure this is in the book, and it's common enough that even someone who doesn't use rust full time (myself) knows it off the top of their head
You can use impl Trait in returns, this is actually one of the reasons why that feature exists.
And yes, you can use generics in an enum.
- howinteresting 6y agoYou have to expose the generic in the enum though. Rust doesn't have existential types at the moment.
- pornel 6y agoI think it's a valid criticism. Ownership, mutability, and thread-safety are not easy to abstract over and hide as implementation details in Rust. It's a side effect of the fact that Rust actually cares about these and checks them strictly, but for users coming from eg Java that's a bit of a shock.