#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

4 releases

0.1.3 May 8, 2024
0.1.2 Mar 14, 2024
0.1.1 Mar 12, 2024
0.1.0 Mar 12, 2024

#308 in Procedural macros

Download history 380/week @ 2024-03-11 8/week @ 2024-03-18 52/week @ 2024-04-01 133/week @ 2024-05-06

133 downloads per month

Custom license

53KB
1.5K SLoC

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

~0.3–0.8MB
~19K SLoC