Skip to content

Commit 1c8a9fe

Browse files
authored
fix(rust): Make new methods consistent for all id params (#306)
1 parent f925dd3 commit 1c8a9fe

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

src/client.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,12 @@ pub struct RequestPermissionRequest {
329329
impl RequestPermissionRequest {
330330
#[must_use]
331331
pub fn new(
332-
session_id: SessionId,
332+
session_id: impl Into<SessionId>,
333333
tool_call: ToolCallUpdate,
334334
options: Vec<PermissionOption>,
335335
) -> Self {
336336
Self {
337-
session_id,
337+
session_id: session_id.into(),
338338
tool_call,
339339
options,
340340
meta: None,
@@ -375,12 +375,12 @@ pub struct PermissionOption {
375375

376376
impl PermissionOption {
377377
pub fn new(
378-
option_id: PermissionOptionId,
378+
option_id: impl Into<PermissionOptionId>,
379379
name: impl Into<String>,
380380
kind: PermissionOptionKind,
381381
) -> Self {
382382
Self {
383-
option_id,
383+
option_id: option_id.into(),
384384
name: name.into(),
385385
kind,
386386
meta: None,
@@ -551,12 +551,12 @@ pub struct WriteTextFileRequest {
551551

552552
impl WriteTextFileRequest {
553553
pub fn new(
554-
session_id: SessionId,
554+
session_id: impl Into<SessionId>,
555555
path: impl Into<PathBuf>,
556556
content: impl Into<String>,
557557
) -> Self {
558558
Self {
559-
session_id,
559+
session_id: session_id.into(),
560560
path: path.into(),
561561
content: content.into(),
562562
meta: None,

src/rpc.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::sync::Arc;
22

3-
use derive_more::Display;
3+
use derive_more::{Display, From};
44
use schemars::JsonSchema;
55
use serde::{Deserialize, Serialize, de::DeserializeOwned};
66
use serde_json::value::RawValue;
@@ -20,13 +20,25 @@ use crate::{
2020
///
2121
/// [2] Fractional parts may be problematic, since many decimal fractions cannot be represented exactly as binary fractions.
2222
#[derive(
23-
Debug, PartialEq, Clone, Hash, Eq, Deserialize, Serialize, PartialOrd, Ord, Display, JsonSchema,
23+
Debug,
24+
PartialEq,
25+
Clone,
26+
Hash,
27+
Eq,
28+
Deserialize,
29+
Serialize,
30+
PartialOrd,
31+
Ord,
32+
Display,
33+
JsonSchema,
34+
From,
2435
)]
2536
#[serde(untagged)]
2637
#[allow(
2738
clippy::exhaustive_enums,
2839
reason = "This comes from the JSON-RPC specification itself"
2940
)]
41+
#[from(String, i64)]
3042
pub enum RequestId {
3143
#[display("null")]
3244
Null,
@@ -60,10 +72,16 @@ pub enum Response<Result> {
6072
}
6173

6274
impl<R> Response<R> {
63-
pub fn new(id: RequestId, result: Result<R>) -> Self {
75+
pub fn new(id: impl Into<RequestId>, result: Result<R>) -> Self {
6476
match result {
65-
Ok(result) => Self::Result { id, result },
66-
Err(error) => Self::Error { id, error },
77+
Ok(result) => Self::Result {
78+
id: id.into(),
79+
result,
80+
},
81+
Err(error) => Self::Error {
82+
id: id.into(),
83+
error,
84+
},
6785
}
6886
}
6987
}

0 commit comments

Comments
 (0)