#traits #parameters #fn #accept #receive #async

macro callback-trait

Implement trait for Fn so that functions that accept traits as parameters can directly receive Fn parameters

3 releases

0.1.2 Mar 14, 2024
0.1.1 Mar 12, 2024
0.1.0 Mar 12, 2024

#252 in Procedural macros

Download history 368/week @ 2024-03-10 20/week @ 2024-03-17 47/week @ 2024-03-31

435 downloads per month

Custom license

34KB
759 lines

callback-trait

Implement trait for Fn so that functions that accept traits as parameters can directly receive Fn parameters, such as:

#[callback_trait]
pub trait ExampleCallback {
	async fn call(&self, p1: u32, p2, u32) -> Result<u32, u32>;
}

fn set_callback(callback: impl ExampleCallback) {
    
}

set_callback(|p1: u32, p2: u32| {
    async move {
        Ok(0)
    }
})

Dependencies

~315–760KB
~18K SLoC