Add methods for unwrapping Result<T, !> / Result<!, E>
Nobody has claimed this yet.
- Dominant language
- Markdown
- Stars
- 6.6k
- Forks
- 1.7k
- Avg merge
- 16h 14m
- Merged PRs (30d)
- 1
Description
One of the main intended uses for the ! type is to be able construct the types Result<T, !> and Result<!, E>. Right now, if you have r: Result<T, !> there are several ways to unpack it's inner T, but none of them are ideal:
r.unwrap():unwrapis scary and should be avoided. This is also fragile if someone later changes the error type to something other than!.r.unwrap_or_else(|e| e): Kinda confusing.let Ok(val) = r;: Requires a separate statement. (Also doesn't currently work).match r { Ok(v) => v, Err(e) => e }: Both long and kinda confusing.match r { Ok(v) => v }: Not as nice as a method onr. (Also doesn't currently work).
The void crate adds the methods void_unwrap and void_unwrap_err to Result<T, Void> and Result<Void, T>. I think methods like these should be added to libcore as well. Perhaps we could call them always_ok() and always_err().
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the issue's examples for Result<T, !> and Result<!, E>, then compare the void crate's void_unwrap and void_unwrap_err methods. The proposed API names are still open; done would require settling the method design and adding the corresponding libcore behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100