3 ms·
A string is the worst thing to return because it’s huge. Most people return () instead which is zero sized. However when returning ! the compiler can optimize
by the_mitsuhiko 8y ago
A string is the worst thing to return because it’s huge. Most people return () instead which is zero sized.
However when returning ! the compiler can optimize the entire error handling away.
- deleted 8y ago[deleted]
- masklinn 8y ago> A string is the worst thing to return because it’s huge. Most people return () instead which is zero sized. I think what they're asking is "if you're returning a Result<String, Err>" but you're making the Err an unhinabitated type (so can't ever have an error) why not just return a String in the first place?
- the_mitsuhiko 8y agoBecause there are generic APIs that return results as part of the contract. A good example is FromStr.
- deleted 8y ago[deleted]
- fnord123 8y agoA string is only like 16bytes (length + pointer to memory in heap) or more if it's a fat pointer.