15 unstable releases (6 breaking)

0.6.1 Aug 24, 2023
0.5.0 Apr 23, 2023
0.4.1 Mar 8, 2023
0.3.3 Nov 1, 2021
0.1.2 Dec 13, 2020
Download history 16/week @ 2023-08-04 22/week @ 2023-08-11 57/week @ 2023-08-18 26/week @ 2023-08-25 9/week @ 2023-09-01 24/week @ 2023-09-08 23/week @ 2023-09-15 9/week @ 2023-09-22 8/week @ 2023-09-29 8/week @ 2023-10-06 9/week @ 2023-10-13 16/week @ 2023-10-20 28/week @ 2023-10-27 20/week @ 2023-11-03 44/week @ 2023-11-10 23/week @ 2023-11-17

116 downloads per month
Used in wd_run


353 lines

wd_event: A async event crate for rust

wd_event GitHub Actions wd_event on crates.io wd_event on docs.rs License

This is a Rust async event Crate. Compared to the previous version, this is a brand new version. Not compatible with previous versions

  • you can customize any type of message event
  • Event handler, which can be a function or trait
  • According to the registration order, the events are executed sequentially and propagated through the online text
  • The event entity is abstract, and you can assemble it as you wish
  • This is an early release and the api may change in the future

Getting Started

wd_event is available on crates.io. It is recommended to look there for the newest released version, as well as links to the newest builds of the docs.

At the point of the last update of this README, the latest published version could be used like this:

Add the following dependency to your Cargo manifest...

wd_event = "0.4"


struct Message<V>{
    id : u64,
    value: V,
impl<V> Message<V> {
    fn new(id:u64,value:V)->Message<V>{
fn generate_event_entity()->Event<EventSchedule>{
        .register(|ctx:Context, mut msg:Message<String>|{
            println!("this is first Message<String> handler ID[{}]--> {}",msg.id,msg.value);
            ctx.next(msg)  // no need async
        .register(|ctx:Context, mut msg:Message<String>|async{
            println!("this is second Message<String> handler ID[{}]--> {}",msg.id,msg.value);
            ctx.next(msg).await //all is async
        .register(|ctx:Context, mut msg:Message<i64>|{
            println!("this is third Message<i64> handle  ID[{}]--> {}",msg.id,msg.value);
            msg.value = 3;
            async move{
                ctx.next(msg).await //part is async

async fn test_message(){
    let event = generate_event_entity();
    let res = event.launch(Context::default(),Message::new(1,"hello world".to_string())).await.expect("first test handle failed");
    assert_eq!(res.value.as_str(),"hello world->one->two","Message<String> result assert failed");
    let res = event.launch(Context::default(),Message::new(1,1i64)).await.expect("second test failed");
    assert_eq!(res.value,3i64,"Message<i64> result assert failed")


  • the event handler executes in the order of registration, ctx.next representing the next handler to execute the event
  • Context can deliver messages in context
  • Settings on context take precedence over global Settings


Licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


~69K SLoC