-
Notifications
You must be signed in to change notification settings - Fork 15
wit/bindgen: generate named result types #335
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
Conversation
28c0bc9
to
c229183
Compare
f3928b7
to
9a5a247
Compare
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.
I like this change personally!
// ResultTupleIncomingDatagramStreamOutgoingDatagramStreamErrorCode represents the imported result "#". | ||
// | ||
// result<tuple<incoming-datagram-stream, outgoing-datagram-stream>, error-code> | ||
type ResultTupleIncomingDatagramStreamOutgoingDatagramStreamErrorCode cm.Result[TupleIncomingDatagramStreamOutgoingDatagramStreamShape, cm.Tuple[IncomingDatagramStream, OutgoingDatagramStream], ErrorCode] |
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.
oh wow this type name is brutally long.
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.
Yeah, this isn’t great.
// Code generated by wit-bindgen-go. DO NOT EDIT. | ||
|
||
package streams | ||
|
||
import ( | ||
"go.bytecodealliance.org/cm" | ||
) | ||
|
||
// ResultListU8StreamError represents the imported result "#". | ||
// | ||
// result<list<u8>, stream-error> | ||
type ResultListU8StreamError cm.Result[cm.List[uint8], cm.List[uint8], StreamError] | ||
|
||
// ResultU64StreamError represents the imported result "#". | ||
// | ||
// result<u64, stream-error> | ||
type ResultU64StreamError cm.Result[uint64, uint64, StreamError] | ||
|
||
// ResultStreamError represents the imported result "#". | ||
// | ||
// result<_, stream-error> | ||
type ResultStreamError cm.Result[StreamError, struct{}, StreamError] |
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.
nice this will reduce the burden of spelling out the shape of the Result type everytime you use it.
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.
I'm not sure it's better!
Not going in this direction. |
This is a rudimentary POC to demonstrate an alternative approach to #331. It generates named Go types for any
result
directly used in a function.It trades Go generic complexity for additional named type surface area. I’m not sure which is better.
Inspired by a suggestion from @Mossaka.