Skip to content

Commit 775d684

Browse files
committed
Added a basic, crude value! macro.
TODO make it use our custom version of the macro instead of converting in runtime
1 parent 673b648 commit 775d684

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/gotham_module.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ extern crate futures;
33
extern crate futures_util;
44
extern crate serde_json;
55

6+
pub use serde_json::json;
7+
68
use crate::{
79
connection::{BaseConnection, Buffer, InetSocketConnection},
810
models::{BaseMessage, Value},
@@ -275,7 +277,7 @@ async fn on_data_listener(
275277
}
276278
Ok(Value::Null)
277279
}
278-
BaseMessage::TriggerHookResponse { .. } => {
280+
BaseMessage::TriggerHookRequest { .. } => {
279281
execute_hook_triggered(message, &hook_listeners).await
280282
}
281283
BaseMessage::Error { error, .. } => Err(Error::FromGotham(error)),
@@ -323,7 +325,7 @@ async fn execute_hook_triggered(
323325
listener(Value::Null);
324326
}
325327
} else {
326-
panic!("Cannot execute function from a request that wasn't a FunctionCallRequest!");
328+
panic!("Cannot execute hook from a request that wasn't a TriggerHookRequest!");
327329
}
328330
Ok(Value::Null)
329331
}

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ pub mod connection;
55
pub mod models;
66
pub mod protocol;
77

8+
#[macro_use]
9+
pub mod macros;
10+
11+
pub use gotham_module::json;
812
pub use gotham_module::GothamModule;

src/macros.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
#[macro_export(local_inner_macros)]
3+
macro_rules! value {
4+
// Hide distracting implementation details from the generated rustdoc.
5+
($($kv:tt)+) => {
6+
json!($($kv)+).into()
7+
};
8+
}

0 commit comments

Comments
 (0)