| Post Reply | RetroFed Forums Forum Index » Rust |
| Author | Message | ||
|---|---|---|---|
SorteKanin
feddit.dk
SorteKanin@feddit.dkJoined: 2023-04-27 |
|
||
| 30 Original | |||
SorteKanin
feddit.dk
SorteKanin@feddit.dkJoined: 2023-04-27 |
So basically their argument is that the missing piece is anonymous sum types. I tend to agree! It would be amazing to have that as a language feature, i.e. |
||
| 13 | |||
|
FizzyOrange
programming.dev
FizzyOrange@programming.dev Joined: 2023-09-24 |
Interesting. I'm surprised that it's possible to use tuples like that. Might try this. |
||
| 9 | |||
|
Ephera
lemmy.ml
Ephera@lemmy.ml Joined: 2020-05-31 |
Damn, this looks like it might solve my pain points with error handling. Will have to see, if it replaces them with new pain points, since error handling is fundamentally hard, but at least, it isn't starting completely from scratch... |
||
| 4 | |||
|
TehPers
beehaw.org
TehPers@beehaw.org Joined: 2023-06-21 |
I like the general idea (not a fan of the syntax but whatever). The one thing I'm not seeing is non-exhaustive error types. For example, in a library, you likely want to say "these errors are known to be possible, and some errors may be added in the future". Without non-exhaustive error types, this would mostly be useful exclusively in applications, not libraries. Of course, syntax-wise, you can just do Either way, I agree that defining errors is needlessly extraordinarily verbose. |
||
| 3 | |||
|
lad
programming.dev
sukhmel@programming.dev Joined: 2023-07-03 |
I like the general idea (not a fan of the syntax but whatever). The one thing I'm not seeing is non-exhaustive error types. For example, in a library, you likely want to say "these errors are known to be possible, and some errors may be added in the future". Without non-exhaustive error types, this would mostly be useful exclusively in applications, not libraries. Of course, syntax-wise, you ca...
I'm not sure non-exhsustive makes sense — you want the caller to handle everything you may return to them, and the new errors won't be handled. Maybe a default branch in the handler could do, though |
||
| 1 | |||
|
TehPers
beehaw.org
TehPers@beehaw.org Joined: 2023-06-21 |
I'm not sure non-exhsustive makes sense — you want the caller to handle everything you may return to them, and the new errors won't be handled. Maybe a default branch in the handler could do, though
This is exactly what it's for. |
||
| 3 | |||
|
Ephera
lemmy.ml
Ephera@lemmy.ml Joined: 2020-05-31 |
I'm not sure non-exhsustive makes sense — you want the caller to handle everything you may return to them, and the new errors won't be handled. Maybe a default branch in the handler could do, though
Had to just think about why Imagine you're developing a really important core library, something like TCP. And then other libraries depend on your library. You have two choices to deal with that:
Obviously, if it's a really egregious new error case that needs specific handling, then you might still want to release version 2.0, but by adding the |
||
| 4 | |||
|
BB_C
programming.dev
BB_C@programming.dev Joined: 2023-07-06 |
So basically their argument is that the missing piece is anonymous sum types. I tend to agree! It would be amazing to have that as a language feature, i.e. Result<(), FooError | BarError>. Unfortunately that is unlikely to arrive to the language for a loooong time... But I think I will definitely try out this library in the meantime.
A language feature is not needed because macros exist. I would even argue that perhaps the most important role macros play is blocking adding endless language features 😉 |
||
| 3 | |||
SorteKanin
feddit.dk
SorteKanin@feddit.dkJoined: 2023-04-27 |
A language feature is not needed because macros exist. I would even argue that perhaps the most important role macros play is blocking adding endless language features 😉
Macros are often not very ergonomical to use compared to language features. Also, why anonymous product types but not anonymous sum types? It seems kind of weird to me. Anonymous sum types can be just as useful as anonymous product types, as the blog post illustrates quite well I think. |
||
| 2 | |||
|
TehPers
beehaw.org
TehPers@beehaw.org Joined: 2023-06-21 |
Macros are often not very ergonomical to use compared to language features. Also, why anonymous product types but not anonymous sum types? It seems kind of weird to me. Anonymous sum types can be just as useful as anonymous product types, as the blog post illustrates quite well I think.
While I agree with you that anonymous sum types are useful, the language designers tend to avoid anything that might include a hidden cost (in this case either the size of the enum or cost of boxing). Something along those lines might end up in the language eventually, though. |
||
| 2 | |||
|
BB_C
programming.dev
BB_C@programming.dev Joined: 2023-07-06 |
Macros are often not very ergonomical to use compared to language features. Also, why anonymous product types but not anonymous sum types? It seems kind of weird to me. Anonymous sum types can be just as useful as anonymous product types, as the blog post illustrates quite well I think.
The language wouldn't have lost much without tuples actually. But they do at least have direct pattern destructuring utility. Anonymous enums don't. They also don't pose potential future awkwardness if/when variant types become a thing. |
||
| 2 | |||
|
lad
programming.dev
sukhmel@programming.dev Joined: 2023-07-03 |
Had to just think about why #[non_exhaustive] exists, so perhaps this helps you as well: Imagine you're developing a really important core library, something like TCP. And then other libraries depend on your library. Now, if you change your implementation, you may need to introduce a new error case, even though the rest of the API still works the same. You have two choices to deal with that: Re...
I have been thinking of semver incorrectly, you're right: https://doc.rust-lang.org/cargo/reference/semver.html#enum-variant-new |
||
| 2 | |||
| Post Reply |
Back to top |