[][src]Attribute Macro hyperbole::record_args

#[record_args]

An attribute macro to reduce boilerplate when writing functions that accept an hlist as an argument (handlers and middlewares).

This will translate the annotated function's argument list into an hlist. Any arguments whose names start with underscores will be translated to their type, while all other arguments will be translated to named fields of their name and type.

Examples

fn f(a: u32, b: u32) translates to fn f(_: R![a: u32, b: u32]).

fn f(a: u32, _b: u32) translates to fn f(_: R![a: u32, u32]).

use hyperbole::{r, record_args, R};

#[record_args]
async fn my_func_a(first: u8, second: String, _third: Vec<u8>) {
    // do stuff
}

// the translated function can be called using record syntax:
my_func_a(r![first = 4, second = "test-string".to_owned(), vec![
    1, 2, 3
]])
.await;

// 'my_func_a' above is translated to something like this:
async fn my_func_b(cx: R![first: u8, second: String, Vec<u8>]) {
    async fn my_func_b(first: u8, second: String, _third: Vec<u8>) {
        // do stuff
    }

    my_func_b(
        cx.head.into_inner(),
        cx.tail.head.into_inner(),
        cx.tail.tail.head,
    )
    .await
}