[−][src]Crate yolo_block
Like a try
block, but automatically unwraps the result. Effectively, inside a yolo!
block, the ?
operator functions as unwrap()
.
The yolo!
macro uses a try
block internally. try
blocks are an unstable feature (as of this writing – Rust 1.43.1), so this crate is only available on nightly, and you must enable #![feature(try_blocks)]
in the crate where you use it.
A single yolo!
block can handle multiple error types. Those error types can be any type that implements Debug. No extra type annotations are needed.
Examples
#![feature(try_blocks)] use yolo_block::yolo; use std::convert::TryFrom; let result = yolo! { "1".parse::<usize>()? + usize::try_from(2i32)? + [0,1,2,3].binary_search(&3)? }; assert_eq!(result, 6);
// Panics with the message "YOLO'd an error: ParseIntError { kind: InvalidDigit }" let result = yolo! { "1".parse::<usize>()? + "foo".parse::<usize>()? + "3".parse::<usize>()? };
Macros
yolo | The macro to create a |