Attribute Macro or_gen

Source
#[or_gen]
Expand description

A proc macro that converts if or match expressions that return multiple types into Or types.

Note that this feature depends on the unstable feature proc_macro_hygiene, so you must add #![feature(proc_macro_hygiene)] annotation when you use it.

§Example: usage for if expression

#![feature(proc_macro_hygiene)]

use or_rs_macros::or_gen;
use or_rs::enums::Or3;

#[or_gen]
// add a type annotation explicitly
let s: Or3<i32, String, f32> = if true {
    3
} else if false {
    "hello".to_string()
} else {
    3.0
};

§Example: usage for match expression

#![feature(proc_macro_hygiene)]

use or_rs_macros::or_gen;
use or_rs::enums::Or3;

#[or_gen]
// add a type annotation explicitly
let s: Or3<i32, f32, String> = match 42 {
    1  => 22,
    10 => 3.2,
    _  => "hello".to_string(),
};