As we move towards stabilising trait Try I'm trying
to collate real-world, actually-implemented, examples.
Anyone who knows of such cases, or has a concrete use case they would like to see, please drop a reply in this thread. For general discussion of Try please start a new thread.
So far, the ones I know about fall into a few categories[1]:
Sidecars
Effectively drop-in replacements for the primary try-types with additional "magic" baked into the Try:
InterpResultin the compiler: adds a guard to ensure correct handlingTraced<T>in tracing_result: stores tracing events & emits them when the wrapped type is propagated or unwrapedTracedResultin traced_result: stores call site information each time?is used to propagateDiagnosticResultin proc_macro2_diagnostic: stores compiler diagnostic messages & emits them when the wrapped type is propagated or unwraped
Ergonomics
Contextin thread_safely: allows for remote cancellation of a thread viacx.cancelled()?
Orphan rule avoidance
- exit_safely: create custom return types for
mainwhich respond to?and implementTerminationwith defined exit codes
Generic over Try
Iterator::try_xxxin std::iter, Box::try_map in std::boxed, etc.: versions of well-known methods which apply fallible functionsExtract&Transformin try_v2: bring.unwrap(),.map(),and_then(), etc. to custom try-types
Background
- Goal: Stabilize the Try trait · Issue #654 · rust-lang/goals
- RFC: 3058-try-trait-v2 - The Rust RFC Book
Disclaimer: many of these are my own publications ↩︎
4 posts - 4 participants
