-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
lang: add E type argument to Result type alias #2731
base: master
Are you sure you want to change the base?
Conversation
Considering that Result is included in Anchor’s prelude, it’s quite annoying when one suddenly needs to use Result with a different error than Anchor’s Error (i.e. use the symbol `Result` like the actual Rust Result type). Add E type argument to Anchar’s Result type-alias so that the symbol can continue to be used like in any Rust code even when someone imports Anchor’s prelude. Specify E’s default value to Anchor’s Error so existing Anchor-based code can continue using the alias as before.
@mina86 is attempting to deploy a commit to the coral-xyz Team on Vercel. A member of the Team first needs to authorize 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.
A pre-defined error type is preferred for libraries e.g. syn::Result
and std::io::Result
.
To me, having generic errors only makes sense if the project is:
- A generic error library like
anyhow
- An application
The problem is that Anchor’s Result is in prelude and importing everything in prelude is recommended way to write Anchor programs (in fact some Anchor macros require it IIRC). The difference with syn::Result or std::io::Result is that if I do |
Yeah, I generally agree with overriding the default |
I don’t understand what you mean by ‘having a known error type’. With my proposed change the error type would still be known. |
By "having a known error type" I mean having Anchor's |
When you write |
I'm aware. |
Considering that Result is included in Anchor’s prelude, it’s quite
annoying when one suddenly needs to use Result with a different error
than Anchor’s Error (i.e. use the symbol
Result
like the actual RustResult type).
Add E type argument to Anchar’s Result type-alias so that the symbol
can continue to be used like in any Rust code even when someone
imports Anchor’s prelude.
Specify E’s default value to Anchor’s Error so existing Anchor-based
code can continue using the alias as before.