Skip to content
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

Merged

Conversation

InsertCreativityHere
Copy link
Member

This PR adds support for a new generic primitive type named Result.
It is syntactically equivalent to a Dictionary, but uses the Result keyword instead.

unchecked enum MyError {}

typealias StringResult = Result<String, MyError>

interface I {
    getBytes() -> Result<Sequence<uint8>, MyError>
}

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, since Result 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:

Result<(a: bool, tag(2), b: string?), MyError>

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.

Copy link
Member

@externl externl left a 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!

@externl
Copy link
Member

externl commented Dec 13, 2023

An action is failing with:

single_line_let_else_max_width cannot have a value that exceeds max_width. single_line_let_else_max_width will be set to the same value as max_width

}

#[test]
fn results_with_optional_keys_are_parsed_correctly() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be optional_ok?

Copy link
Member Author

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.

}

#[test]
fn results_with_optional_values_are_parsed_correctly() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optinal_err?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

@InsertCreativityHere InsertCreativityHere merged commit 4f53496 into icerpc:main Dec 13, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants