Skip to content

Commit fb4cc06

Browse files
committed
refactor & README
1 parent ccb7db8 commit fb4cc06

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
# jsonrpc2-rs
22

3-
A simple JSON-RPC 2.0 client/server library in rust.
3+
4+
[![crates.io](https://img.shields.io/crates/v/jrpc2.svg)](https://crates.io/crates/jrpc2)
5+
6+
A JSON-RPC 2.0 client/server library in rust.

src/jsonrpc2.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -348,14 +348,18 @@ mod tests {
348348
assert_eq!(response_any, data_response);
349349
}
350350

351+
type ResponseResult = u32;
352+
type ErrorData = String;
353+
type RequestParams = Vec<u32>;
354+
351355
struct Add {}
352356

353357
#[async_trait]
354-
impl THandler<Vec<u32>, u32, String> for Add {
358+
impl THandler<RequestParams, ResponseResult, ErrorData> for Add {
355359
async fn handle(
356360
&self,
357-
json_rpc2: Arc<JsonRpc2<Vec<u32>, u32, String>>,
358-
request: Request<Vec<u32>>,
361+
json_rpc2: Arc<JsonRpc2<RequestParams, ResponseResult, ErrorData>>,
362+
request: Request<RequestParams>,
359363
) {
360364
match request.method.as_str() {
361365
"add" => {
@@ -399,16 +403,15 @@ mod tests {
399403
.await
400404
.expect("cannot generate object stream");
401405

402-
let conn_arc = JsonRpc2::<_, u32, String>::new(Box::new(client_stream), None).await;
406+
let conn_arc =
407+
JsonRpc2::<_, ResponseResult, ErrorData>::new(Box::new(client_stream), None).await;
403408

404409
time::sleep(time::Duration::new(2, 0)).await;
405-
println!("adfadfadf");
406410
match conn_arc.call("add", Some(vec![2u32, 3u32, 4u32])).await {
407411
Ok(response) => {
408412
let result = response.result.unwrap();
409-
print!("result: {}", result);
413+
410414
assert_eq!(result, 9);
411-
println!("adfadfadf===");
412415
}
413416
Err(err) => {
414417
log::error!("call add error: {}", err);

0 commit comments

Comments
 (0)