What is the idiomatic way to return an error from a function with no result if successful?

Use fn do_work() -> Result<(), WorkError>.

Result<(), WorkError> means you want the work to be done, but it may fail.

Option<WorkError> means you want to get an error, but it may be absent.

You probably want the work to be done but not to get an error when you write do_work(), so Result<(), WorkError> is the better choice.

I would expect Option<WorkError> only be used in cases like fn get_last_work_error() -> Option<WorkError>.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)