Merge pull request #11 from Trivernis/develop

Add events macro and change provider to provide static strings
pull/24/head
Julius Riegel 3 years ago committed by GitHub
commit 7fe8b4a734
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

2
Cargo.lock generated

@ -148,7 +148,7 @@ dependencies = [
[[package]]
name = "rmp-ipc"
version = "0.5.0"
version = "0.6.0"
dependencies = [
"lazy_static",
"log",

@ -1,6 +1,6 @@
[package]
name = "rmp-ipc"
version = "0.5.0"
version = "0.6.0"
authors = ["trivernis <trivernis@protonmail.com>"]
edition = "2018"
readme = "README.md"

@ -89,10 +89,12 @@ impl MyNamespace {
}
impl NamespaceProvider for MyNamespace {
fn name() -> String {String::from("my_namespace")}
fn name() -> &'static str {"my_namespace"}
fn register(handler: &mut EventHandler) {
handler.on("ping", callback!(Self::ping))
events!(handler,
"ping" => Self::ping
);
}
}

@ -22,10 +22,13 @@
//! }
//!
//! impl NamespaceProvider for MyNamespace {
//! fn name() -> String {String::from("my_namespace")}
//! fn name() -> &'static str {"my_namespace"}
//!
//! fn register(handler: &mut EventHandler) {
//! handler.on("ping", callback!(Self::ping))
//! events!(handler,
//! "ping" => Self::ping,
//! "ping2" => Self::ping
//! );
//! }
//!}
//!

@ -17,3 +17,17 @@ macro_rules! namespace {
Namespace::from_provider::<$nsp>()
};
}
#[macro_export]
macro_rules! events{
($handler:expr, $($name:expr => $cb:ident), *) => {
$(
$handler.on($name, callback!($cb));
)*
};
($handler:expr, $($name:expr => $cb:path), *) => {
$(
$handler.on($name, callback!($cb));
)*
}
}

@ -2,7 +2,7 @@ use crate::events::event_handler::EventHandler;
use crate::namespace::Namespace;
pub trait NamespaceProvider {
fn name() -> String;
fn name() -> &'static str;
fn register(handler: &mut EventHandler);
}

@ -75,12 +75,15 @@ impl TestNamespace {
}
impl NamespaceProvider for TestNamespace {
fn name() -> String {
String::from("Test")
fn name() -> &'static str {
"Test"
}
fn register(handler: &mut EventHandler) {
handler.on("ping", callback!(Self::ping))
events!(handler,
"ping" => Self::ping,
"ping2" => Self::ping
);
}
}

Loading…
Cancel
Save