Crates.io | or-rs-macros |
lib.rs | or-rs-macros |
version | 0.1.1 |
source | src |
created_at | 2023-12-17 14:18:25.1771 |
updated_at | 2024-01-03 20:16:38.871108 |
description | or-rs's proc macros. |
homepage | |
repository | https://github.com/mox692/or-rs |
max_upload_size | |
id | 1072527 |
size | 17,364 |
or_gen
Proc Macro DocumentationA proc macro that converts if
or match
expressions that return multiple types into Or types.
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
};
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(),
};
#[proc_macro_attribute]
pub fn or_gen(_attr: TokenStream, item: TokenStream) -> TokenStream {
parser::MacroParser::parse(item)
}