Skip to content

Commit ff8005f

Browse files
committed
Modify Hook trait to pass RequestId by value instead of reference
- Update `Hook` trait method signature to take `RequestId` by value - Adjust implementations and usages in `lib.rs` and `tests/session.rs` - Remove unnecessary reference passing for `RequestId`
1 parent 8c019dc commit ff8005f

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ pub trait Handler {
5353
impl Handler for () {}
5454

5555
pub trait Hook: Send + Sync {
56-
fn cancel_outgoing_request(&self, id: &RequestId, session: &SessionContext);
56+
fn cancel_outgoing_request(&self, id: RequestId, session: &SessionContext);
5757
}
5858
impl Hook for () {
59-
fn cancel_outgoing_request(&self, _id: &RequestId, _session: &SessionContext) {}
59+
fn cancel_outgoing_request(&self, _id: RequestId, _session: &SessionContext) {}
6060
}
6161

6262
pub const NO_PARAMS: Option<&()> = None;
@@ -849,7 +849,7 @@ impl RawSession {
849849
while self.fetch_outgoing_cancellations(&mut id_reader).await {
850850
let session_ctx = SessionContext::new(self);
851851
for id in &mut id_reader {
852-
self.hook.cancel_outgoing_request(&id.into(), &session_ctx);
852+
self.hook.cancel_outgoing_request(id.into(), &session_ctx);
853853
}
854854
}
855855
Ok(())

tests/session.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use std::{sync::Arc, time::Duration};
22

33
use assert_call::{call, Call, CallRecorder};
44
use jsoncall::{
5-
ErrorCode, ErrorObject, Handler, Hook, NotificationContext, Params, RequestContext, Response,
6-
Result, Session, SessionContext, SessionError, SessionErrorKind, NO_PARAMS,
5+
ErrorCode, ErrorObject, Handler, Hook, NotificationContext, Params, RequestContext, RequestId,
6+
Response, Result, Session, SessionContext, SessionError, SessionErrorKind, NO_PARAMS,
77
};
88
use serde::{Deserialize, Serialize};
99
use tokio::{
@@ -528,9 +528,9 @@ impl Handler for HelloService {
528528
fn hook(&self) -> Arc<dyn jsoncall::Hook> {
529529
struct TestHook;
530530
impl Hook for TestHook {
531-
fn cancel_outgoing_request(&self, id: &jsoncall::RequestId, session: &SessionContext) {
531+
fn cancel_outgoing_request(&self, id: RequestId, session: &SessionContext) {
532532
call!("cancel_outgoing_request");
533-
let _ = session.notification("cancel", Some(id));
533+
let _ = session.notification("cancel", Some(&id));
534534
}
535535
}
536536

@@ -643,7 +643,7 @@ impl Handler for HelloService {
643643
"notify" => cx.handle(this.notify(params.to()?)),
644644
"notify_async" => cx.handle_async(this.notify_async(params.to()?)),
645645
"cancel" => {
646-
let request_id: jsoncall::RequestId = params.to()?;
646+
let request_id: RequestId = params.to()?;
647647
cx.session().cancel_incoming_request(&request_id, None);
648648
cx.handle(Ok(()))
649649
}

0 commit comments

Comments
 (0)