-
Notifications
You must be signed in to change notification settings - Fork 5
Add Result Type Support #687
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Result Type Support #687
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
An action is failing with:
|
tests/optional_tests.rs
Outdated
} | ||
|
||
#[test] | ||
fn results_with_optional_keys_are_parsed_correctly() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be optional_ok
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, good catch!
I copied the dictionary tests, a little too sloppily apparently.
tests/optional_tests.rs
Outdated
} | ||
|
||
#[test] | ||
fn results_with_optional_values_are_parsed_correctly() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optinal_err
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same.
This PR adds support for a new generic primitive type named
Result
.It is syntactically equivalent to a
Dictionary
, but uses theResult
keyword instead.Result
is a Slice2 only feature. It can be used anywhere a type can be.It is logically equivalent to a compact enum with 2 variants for 'ok' and 'error'.
Internally in the compiler, I named it
ResultType
, sinceResult
is a heavily used type in Rust.Deviations from the original proposal (#682)
In the original proposal, we wanted to support tuples in the
Ok
type:However this implementation does not support this, since we never added support for first-class tuples to Slice.
Both type parameters for
Result
must be Slice types.We can always change this in the future, but note there is no lack of functionality.
Users must simply convert their tuple into a struct, and then that struct can be used.