|
|
|
|
|
by hammerdr
3956 days ago
|
|
Warning: very little knowledge of Rust and Iron Can someone explain why there is an extra Ok(...) in this? (I want to call it a function, but I'm not even familiar enough with Rust to be sure that it is a function). Is it something that could be removed? Right now it just looks like boilerplate. Edit: Thanks everyone! Ok is similar to a Right or Success of a Either/Result type of object. |
|
In other languages/frameworks (python/pecan for example) you'd throw an exception in case of things going wrong. In Rust exceptions are for very exceptional things only (it's called panic). So the more calm way is just to return `Err(...)`.
It's not a function, it's more like a tagged union (in rust called an enum). So in practice it's like C's union, but you do know which member was chosen and only that one is accessible.