4 ms·
"Funny" code. I'm quite sure nobody would do something like that "in production"… The problem starts with the signature of this function: There is—of course—n
by still_grokking 4y ago
"Funny" code.
I'm quite sure nobody would do something like that "in production"…
The problem starts with the signature of this function: There is—of course—no function which could take an arbitrary String and return a SubscriberName.
You need to return at least an Option, or better a Result.
But at this point the fun starts. You need to thread this wrapped value throughout your whole program.
Crashing your program (by a panic in the above function, or by a unwrap somewhere later) because someone sent you an invalid String is not an option in real life.
- satvikpendem 4y agoThat's a simplified example that I grabbed in the middle of the book before the author refactors it, of course you shouldn't `panic` if you don't need to.
- still_grokking 4y agoI've pointed this out as I think the follow-up problem is more difficult actually. It's easy to validate something "and just throw an exception". The fun starts when you can't do that (or don't want to do it like that).