The base constructor for YourStructshould be a static method called YourStruct::new()(for more details, see Rust Style Guides ).
For the return type, use YourStructif nothing goes wrong, or if you use fail!(). Use Option<YourStruct>if there is only one obvious reason for the failure of the constructor. Use Result<YourStruct, YourStructErr>if it would be useful for the caller to find out why he failed. The problem with this fail!()is that it prevents the caller from retrying or sending a message with a good message to the user, or anything else that the caller can do. In certain situations, it fail!()may be in order.
source
share