IceRPC 0.3 adds Discriminated Unions and Result to Slice #3941
bernardnormier
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We are delighted to announce the release of IceRPC 0.3.0 for C#!
This release refines the Slice language with the addition of discriminated unions and the new Result<Success, Failure> type. Give it a try and let us know what you think!
Discriminated Union
You define a discriminated union in Slice with the enum construct, just like in Rust and Swift. The enumerators of a Slice enum without an underlying type can define fields. Such an "enum with fields" is a discriminated union.
For example, you can define a typical Shape discriminated union as follows:
You can then use
Shape
like any other Slice type - as the type of an operation parameter, as the field of a struct, or even as the field of another enumerator.The updated enum type page in the IceRPC docs provides all the details. You can also see this new syntax in the DiscriminatedUnion example.
Result<Success, Failure>
A Slice operation can return one or more return values, and until now there was no simple way to express "this value is returned upon successfully completion, while that value is returned upon failure".
Discriminated unions provide an elegant solution. You can create a discriminated union and use it as the return type for your operation:
Nevertheless, defining numerous Result enums would be tedious and reduce readability. So we introduced a new Result generic type that provides the above with a much more succinct syntax:
See the Result type page in the IceRPC docs for more information. Or try the new CustomError example.
Beta Was this translation helpful? Give feedback.
All reactions