meta/
meta.rs

1use jsonrpc_core::*;
2
3#[derive(Clone, Default)]
4struct Meta(usize);
5impl Metadata for Meta {}
6
7pub fn main() {
8	let mut io = MetaIoHandler::default();
9
10	io.add_method_with_meta("say_hello", |_params: Params, meta: Meta| async move {
11		Ok(Value::String(format!("Hello World: {}", meta.0)))
12	});
13
14	let request = r#"{"jsonrpc": "2.0", "method": "say_hello", "params": [42, 23], "id": 1}"#;
15	let response = r#"{"jsonrpc":"2.0","result":"Hello World: 5","id":1}"#;
16
17	let headers = 5;
18	assert_eq!(
19		io.handle_request_sync(request, Meta(headers)),
20		Some(response.to_owned())
21	);
22}