This is normally used as a return value for operations which can fail: E is
short for Error. A can be thought of as the success value, and E is the
error value. This is reflected in their constructors: to construct a success
value, you call Ok, and to construct an error value, you call
Err.
You can also use the Result.await function to convert a
Promise that could throw an exception into a Promise that
won't throw but instead returns a Result containing either the error
or the expected result, or the Result.try function to run a function
and catch any exceptions into a Result return value.
A value which can be of either type
A
or typeE
.This is normally used as a return value for operations which can fail:
E
is short forError
.A
can be thought of as the success value, andE
is the error value. This is reflected in their constructors: to construct a success value, you call Ok, and to construct an error value, you call Err.You can also use the Result.await function to convert a Promise that could throw an exception into a Promise that won't throw but instead returns a Result containing either the error or the expected result, or the Result.try function to run a function and catch any exceptions into a Result return value.