Skip to content

Commit dd0141a

Browse files
committed
rfc, try-expr: discuss wrap as an alternative.
1 parent 42331a9 commit dd0141a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

text/0000-try-expr.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,32 @@ However, `trap` is used as an error handler in at least one langauge.
478478
It also does not have the familiarity that `try` does have and is entirely
479479
inconsistent wrt. naming in the standard library.
480480

481+
## Alternative: reserving `wrap`
482+
483+
1. **Fidelity to the construct's actual behavior:** Somewhat good
484+
2. **Precedent from existing languages:** None
485+
3. **Brevity / Length:** 4
486+
4. **Consistency with the naming of the trait used for `?`:** Inconsistent
487+
5. **Consistency with related libstd fn conventions:** Inconsistent
488+
6. **Risk of breakage:** Very low
489+
- **Used in std:** [*No*](https://doc.rust-lang.org/nightly/std/?search=wrap)
490+
- **Used as crate?** [*Yes*](https://crates.io/crates/wrap), no reverse dependencies.
491+
- **Usage (sourcegraph):** **37+** regex:
492+
```
493+
repogroup:crates case:yes max:400
494+
\b((let|const|type|)\s+wrap\s+=|(fn|impl|mod|struct|enum|union|trait)\s+wrap)\b
495+
```
496+
7. **Consistency with old learning material:** Untaught
497+
498+
### Review
499+
500+
With `wrap { .. }` we can say that it "wraps" the result of the block as a
501+
`Result` / `Option`, etc. and it is logically related to `.unwrap()`,
502+
which is however a partial function, wherefore the connotation might be bad.
503+
504+
Also, `wrap` could be considered too generic as with `do` in that it could
505+
fit for any monad.
506+
481507
## Alternative: reserving `result`
482508

483509
1. **Fidelity to the construct's actual behavior:** Somewhat good

0 commit comments

Comments
 (0)