Skip to content

Commit a38f361

Browse files
authored
Minor Rust style cleanups (#101)
Signed-off-by: Ben Brandt <benjamin.j.brandt@gmail.com>
1 parent 8336796 commit a38f361

9 files changed

Lines changed: 92 additions & 88 deletions

File tree

rust/acp.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl Agent for ClientSideConnection {
184184
Some(ClientRequest::AuthenticateRequest(args)),
185185
)
186186
.await
187-
.map(|value| value.unwrap_or_default())
187+
.map(Option::unwrap_or_default)
188188
}
189189

190190
async fn new_session(&self, args: NewSessionRequest) -> Result<NewSessionResponse, Error> {
@@ -203,7 +203,7 @@ impl Agent for ClientSideConnection {
203203
Some(ClientRequest::LoadSessionRequest(args)),
204204
)
205205
.await
206-
.map(|value| value.unwrap_or_default())
206+
.map(Option::unwrap_or_default)
207207
}
208208

209209
async fn set_session_mode(
@@ -466,7 +466,7 @@ impl Client for AgentSideConnection {
466466
Some(AgentRequest::WriteTextFileRequest(args)),
467467
)
468468
.await
469-
.map(|value| value.unwrap_or_default())
469+
.map(Option::unwrap_or_default)
470470
}
471471

472472
async fn read_text_file(
@@ -515,7 +515,7 @@ impl Client for AgentSideConnection {
515515
Some(AgentRequest::ReleaseTerminalRequest(args)),
516516
)
517517
.await
518-
.map(|value| value.unwrap_or_default())
518+
.map(Option::unwrap_or_default)
519519
}
520520

521521
async fn wait_for_terminal_exit(
@@ -540,7 +540,7 @@ impl Client for AgentSideConnection {
540540
Some(AgentRequest::KillTerminalCommandRequest(args)),
541541
)
542542
.await
543-
.map(|value| value.unwrap_or_default())
543+
.map(Option::unwrap_or_default)
544544
}
545545

546546
async fn session_notification(&self, args: SessionNotification) -> Result<(), Error> {

rust/agent.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ pub enum ClientRequest {
658658
/// This enum is used internally for routing RPC responses. You typically won't need
659659
/// to use this directly - the responses are handled automatically by the connection.
660660
///
661-
/// These are responses to the corresponding ClientRequest variants.
661+
/// These are responses to the corresponding `ClientRequest` variants.
662662
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
663663
#[serde(untagged)]
664664
#[schemars(extend("x-docs-ignore" = true))]

rust/client.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ pub enum SessionUpdate {
219219
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
220220
#[serde(rename_all = "camelCase")]
221221
pub struct AvailableCommand {
222-
/// Command name (e.g., "create_plan", "research_codebase").
222+
/// Command name (e.g., `create_plan`, `research_codebase`).
223223
pub name: String,
224224
/// Human-readable description of what the command does.
225225
pub description: String,
@@ -359,7 +359,7 @@ pub struct WriteTextFileRequest {
359359
pub meta: Option<serde_json::Value>,
360360
}
361361

362-
/// Response to fs/write_text_file
362+
/// Response to `fs/write_text_file`
363363
#[derive(Default, Debug, Clone, Serialize, Deserialize, JsonSchema)]
364364
#[serde(rename_all = "camelCase")]
365365
#[schemars(extend("x-side" = "client", "x-method" = FS_WRITE_TEXT_FILE_METHOD_NAME))]
@@ -706,7 +706,7 @@ pub enum AgentRequest {
706706
/// This enum is used internally for routing RPC responses. You typically won't need
707707
/// to use this directly - the responses are handled automatically by the connection.
708708
///
709-
/// These are responses to the corresponding AgentRequest variants.
709+
/// These are responses to the corresponding `AgentRequest` variants.
710710
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
711711
#[serde(untagged)]
712712
#[schemars(extend("x-docs-ignore" = true))]

rust/error.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//!
1111
//! See: [Error Handling](https://agentclientprotocol.com/protocol/overview#error-handling)
1212
13-
use std::{fmt::Display, ops::Deref as _};
13+
use std::fmt::Display;
1414

1515
use schemars::JsonSchema;
1616
use serde::{Deserialize, Serialize};
@@ -52,37 +52,44 @@ impl Error {
5252
///
5353
/// This method is chainable and allows attaching context-specific information
5454
/// to help with debugging or provide more details about the error.
55+
#[must_use]
5556
pub fn with_data(mut self, data: impl Into<serde_json::Value>) -> Self {
5657
self.data = Some(data.into());
5758
self
5859
}
5960

6061
/// Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.
62+
#[must_use]
6163
pub fn parse_error() -> Self {
6264
Error::new(ErrorCode::PARSE_ERROR)
6365
}
6466

6567
/// The JSON sent is not a valid Request object.
68+
#[must_use]
6669
pub fn invalid_request() -> Self {
6770
Error::new(ErrorCode::INVALID_REQUEST)
6871
}
6972

7073
/// The method does not exist / is not available.
74+
#[must_use]
7175
pub fn method_not_found() -> Self {
7276
Error::new(ErrorCode::METHOD_NOT_FOUND)
7377
}
7478

7579
/// Invalid method parameter(s).
80+
#[must_use]
7681
pub fn invalid_params() -> Self {
7782
Error::new(ErrorCode::INVALID_PARAMS)
7883
}
7984

8085
/// Internal JSON-RPC error.
86+
#[must_use]
8187
pub fn internal_error() -> Self {
8288
Error::new(ErrorCode::INTERNAL_ERROR)
8389
}
8490

8591
/// Authentication required.
92+
#[must_use]
8693
pub fn auth_required() -> Self {
8794
Error::new(ErrorCode::AUTH_REQUIRED)
8895
}
@@ -181,7 +188,7 @@ impl Display for Error {
181188

182189
impl From<anyhow::Error> for Error {
183190
fn from(error: anyhow::Error) -> Self {
184-
Error::into_internal_error(error.deref())
191+
Error::into_internal_error(&*error)
185192
}
186193
}
187194

rust/example_agent.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::cell::Cell;
1616

1717
use agent_client_protocol::{
1818
self as acp, AuthenticateResponse, Client, ExtNotification, ExtRequest, ExtResponse,
19-
SessionNotification,
19+
SessionNotification, SetSessionModeResponse,
2020
};
2121
use serde_json::json;
2222
use tokio::sync::{mpsc, oneshot};
@@ -58,7 +58,7 @@ impl acp::Agent for ExampleAgent {
5858
arguments: acp::AuthenticateRequest,
5959
) -> Result<AuthenticateResponse, acp::Error> {
6060
log::info!("Received authenticate request {arguments:?}");
61-
Ok(Default::default())
61+
Ok(AuthenticateResponse::default())
6262
}
6363

6464
async fn new_session(
@@ -121,7 +121,7 @@ impl acp::Agent for ExampleAgent {
121121
args: acp::SetSessionModeRequest,
122122
) -> Result<acp::SetSessionModeResponse, acp::Error> {
123123
log::info!("Received set session mode request {args:?}");
124-
Ok(Default::default())
124+
Ok(SetSessionModeResponse::default())
125125
}
126126

127127
async fn ext_method(&self, args: ExtRequest) -> Result<ExtResponse, acp::Error> {

0 commit comments

Comments
 (0)