[][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.


use yolo_block::yolo;
use std::convert::TryFrom;

let result = yolo! {
        + 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! {
        + "foo".parse::<usize>()?
        + "3".parse::<usize>()?



The macro to create a yolo! block.