or-rs-macros

Crates.ioor-rs-macros
lib.rsor-rs-macros
version0.1.1
sourcesrc
created_at2023-12-17 14:18:25.1771
updated_at2024-01-03 20:16:38.871108
descriptionor-rs's proc macros.
homepage
repositoryhttps://github.com/mox692/or-rs
max_upload_size
id1072527
size17,364
Motoyuki Kimura (mox692)

documentation

README

or_gen Proc Macro Documentation

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

Usage Examples

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
};

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(),
};

Function Definition

#[proc_macro_attribute]
pub fn or_gen(_attr: TokenStream, item: TokenStream) -> TokenStream {
    parser::MacroParser::parse(item)
}
Commit count: 10

cargo fmt