noon 0.1.1

Strongly-typed, compile-time mediator
Documentation
  • Coverage
  • 2.33%
    1 out of 43 items documented1 out of 38 items with examples
  • Size
  • Source code size: 18.67 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 3.64 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Homepage
  • toshokan/noon
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • toshokan

noon

Crates.io Crates.io docs.rs

Strongly-typed, compile-time mediator.

Documentation

See the documentation on docs.rs

Example

use noon::mediator::{Mediate, MediatorBuilder};

// Create message types
struct NewUserRequest { id: i32 };
struct NewUserResponse { total_users: u32 };
struct SendUserEmail { id: i32, msg: String };
struct NewUserLogin { id: i32 };

async fn foo() {
    // Create a mediator
    let mediator = MediatorBuilder::new()
        .add_handler(|x: NewUserRequest| {
            // get total users
            NewUserResponse { total_users: 13 }
        })
        .add_async_handler(|x: SendUserEmail| async move {
            // send email
            true
        })
        .listen_for::<NewUserLogin>()
        .add_notification_receiver(|x: &NewUserLogin| {
            println!("User {} logged in!", x.id);
        })
        .build();
        
    mediator.notify(&NewUserLogin { id: 5 });
    let response = mediator.handle(NewUserRequest { id: 5 });
    println!("There are now {} users in the system", response.total_users);
}

let mediator = MediatorBuilder::new()
    .build();

License

noon is dual licensed under the terms of the MIT or Apache-2.0 licenses. You may choose whichever you prefer.