diff --git a/src/agent.rs b/src/agent.rs index 0b144b73..f5b1fa03 100644 --- a/src/agent.rs +++ b/src/agent.rs @@ -193,6 +193,7 @@ pub struct Implementation { } impl Implementation { + #[must_use] pub fn new(name: impl Into, version: impl Into) -> Self { Self { name: name.into(), @@ -297,6 +298,7 @@ impl AuthenticateResponse { pub struct AuthMethodId(pub Arc); impl AuthMethodId { + #[must_use] pub fn new(id: impl Into>) -> Self { Self(id.into()) } @@ -393,6 +395,7 @@ pub struct AuthMethodAgent { } impl AuthMethodAgent { + #[must_use] pub fn new(id: impl Into, name: impl Into) -> Self { Self { id: id.into(), @@ -456,6 +459,7 @@ pub struct AuthMethodEnvVar { #[cfg(feature = "unstable_auth_methods")] impl AuthMethodEnvVar { + #[must_use] pub fn new( id: impl Into, name: impl Into, @@ -473,8 +477,8 @@ impl AuthMethodEnvVar { /// Optional link to a page where the user can obtain their credentials. #[must_use] - pub fn link(mut self, link: impl Into) -> Self { - self.link = Some(link.into()); + pub fn link(mut self, link: impl IntoOption) -> Self { + self.link = link.into_option(); self } @@ -554,6 +558,7 @@ fn is_false(v: &bool) -> bool { #[cfg(feature = "unstable_auth_methods")] impl AuthEnvVar { /// Creates a new auth env var. + #[must_use] pub fn new(name: impl Into) -> Self { Self { name: name.into(), @@ -566,8 +571,8 @@ impl AuthEnvVar { /// Human-readable label for this variable, displayed in client UI. #[must_use] - pub fn label(mut self, label: impl Into) -> Self { - self.label = Some(label.into()); + pub fn label(mut self, label: impl IntoOption) -> Self { + self.label = label.into_option(); self } @@ -634,6 +639,7 @@ pub struct AuthMethodTerminal { #[cfg(feature = "unstable_auth_methods")] impl AuthMethodTerminal { + #[must_use] pub fn new(id: impl Into, name: impl Into) -> Self { Self { id: id.into(), @@ -702,6 +708,7 @@ pub struct NewSessionRequest { } impl NewSessionRequest { + #[must_use] pub fn new(cwd: impl Into) -> Self { Self { cwd: cwd.into(), @@ -850,6 +857,7 @@ pub struct LoadSessionRequest { } impl LoadSessionRequest { + #[must_use] pub fn new(session_id: impl Into, cwd: impl Into) -> Self { Self { mcp_servers: vec![], @@ -994,6 +1002,7 @@ pub struct ForkSessionRequest { #[cfg(feature = "unstable_session_fork")] impl ForkSessionRequest { + #[must_use] pub fn new(session_id: impl Into, cwd: impl Into) -> Self { Self { session_id: session_id.into(), @@ -1153,6 +1162,7 @@ pub struct ResumeSessionRequest { #[cfg(feature = "unstable_session_resume")] impl ResumeSessionRequest { + #[must_use] pub fn new(session_id: impl Into, cwd: impl Into) -> Self { Self { session_id: session_id.into(), @@ -1507,6 +1517,7 @@ pub struct SessionInfo { #[cfg(feature = "unstable_session_list")] impl SessionInfo { + #[must_use] pub fn new(session_id: impl Into, cwd: impl Into) -> Self { Self { session_id: session_id.into(), @@ -1609,6 +1620,7 @@ pub struct SessionMode { } impl SessionMode { + #[must_use] pub fn new(id: impl Into, name: impl Into) -> Self { Self { id: id.into(), @@ -1644,6 +1656,7 @@ impl SessionMode { pub struct SessionModeId(pub Arc); impl SessionModeId { + #[must_use] pub fn new(id: impl Into>) -> Self { Self(id.into()) } @@ -1718,6 +1731,7 @@ impl SetSessionModeResponse { pub struct SessionConfigId(pub Arc); impl SessionConfigId { + #[must_use] pub fn new(id: impl Into>) -> Self { Self(id.into()) } @@ -1731,6 +1745,7 @@ impl SessionConfigId { pub struct SessionConfigValueId(pub Arc); impl SessionConfigValueId { + #[must_use] pub fn new(id: impl Into>) -> Self { Self(id.into()) } @@ -1744,6 +1759,7 @@ impl SessionConfigValueId { pub struct SessionConfigGroupId(pub Arc); impl SessionConfigGroupId { + #[must_use] pub fn new(id: impl Into>) -> Self { Self(id.into()) } @@ -2143,6 +2159,7 @@ pub struct McpServerHttp { } impl McpServerHttp { + #[must_use] pub fn new(name: impl Into, url: impl Into) -> Self { Self { name: name.into(), @@ -2192,6 +2209,7 @@ pub struct McpServerSse { } impl McpServerSse { + #[must_use] pub fn new(name: impl Into, url: impl Into) -> Self { Self { name: name.into(), @@ -2243,6 +2261,7 @@ pub struct McpServerStdio { } impl McpServerStdio { + #[must_use] pub fn new(name: impl Into, command: impl Into) -> Self { Self { name: name.into(), @@ -2298,6 +2317,7 @@ pub struct EnvVariable { } impl EnvVariable { + #[must_use] pub fn new(name: impl Into, value: impl Into) -> Self { Self { name: name.into(), @@ -2337,6 +2357,7 @@ pub struct HttpHeader { } impl HttpHeader { + #[must_use] pub fn new(name: impl Into, value: impl Into) -> Self { Self { name: name.into(), @@ -2690,6 +2711,7 @@ pub struct ModelId(pub Arc); #[cfg(feature = "unstable_session_model")] impl ModelId { + #[must_use] pub fn new(id: impl Into>) -> Self { Self(id.into()) } @@ -2723,6 +2745,7 @@ pub struct ModelInfo { #[cfg(feature = "unstable_session_model")] impl ModelInfo { + #[must_use] pub fn new(model_id: impl Into, name: impl Into) -> Self { Self { model_id: model_id.into(), diff --git a/src/client.rs b/src/client.rs index 76844bfa..c58f9f98 100644 --- a/src/client.rs +++ b/src/client.rs @@ -448,6 +448,7 @@ pub struct AvailableCommand { } impl AvailableCommand { + #[must_use] pub fn new(name: impl Into, description: impl Into) -> Self { Self { name: name.into(), @@ -502,6 +503,7 @@ pub struct UnstructuredCommandInput { } impl UnstructuredCommandInput { + #[must_use] pub fn new(hint: impl Into) -> Self { Self { hint: hint.into(), @@ -596,6 +598,7 @@ pub struct PermissionOption { } impl PermissionOption { + #[must_use] pub fn new( option_id: impl Into, name: impl Into, @@ -629,6 +632,7 @@ impl PermissionOption { pub struct PermissionOptionId(pub Arc); impl PermissionOptionId { + #[must_use] pub fn new(id: impl Into>) -> Self { Self(id.into()) } @@ -772,6 +776,7 @@ pub struct WriteTextFileRequest { } impl WriteTextFileRequest { + #[must_use] pub fn new( session_id: impl Into, path: impl Into, @@ -860,6 +865,7 @@ pub struct ReadTextFileRequest { } impl ReadTextFileRequest { + #[must_use] pub fn new(session_id: impl Into, path: impl Into) -> Self { Self { session_id: session_id.into(), @@ -913,6 +919,7 @@ pub struct ReadTextFileResponse { } impl ReadTextFileResponse { + #[must_use] pub fn new(content: impl Into) -> Self { Self { content: content.into(), @@ -941,6 +948,7 @@ impl ReadTextFileResponse { pub struct TerminalId(pub Arc); impl TerminalId { + #[must_use] pub fn new(id: impl Into>) -> Self { Self(id.into()) } @@ -985,6 +993,7 @@ pub struct CreateTerminalRequest { } impl CreateTerminalRequest { + #[must_use] pub fn new(session_id: impl Into, command: impl Into) -> Self { Self { session_id: session_id.into(), @@ -1145,6 +1154,7 @@ pub struct TerminalOutputResponse { } impl TerminalOutputResponse { + #[must_use] pub fn new(output: impl Into, truncated: bool) -> Self { Self { output: output.into(), diff --git a/src/content.rs b/src/content.rs index 7760ba56..123982bb 100644 --- a/src/content.rs +++ b/src/content.rs @@ -75,6 +75,7 @@ pub struct TextContent { } impl TextContent { + #[must_use] pub fn new(text: impl Into) -> Self { Self { annotations: None, @@ -128,6 +129,7 @@ pub struct ImageContent { } impl ImageContent { + #[must_use] pub fn new(data: impl Into, mime_type: impl Into) -> Self { Self { annotations: None, @@ -181,6 +183,7 @@ pub struct AudioContent { } impl AudioContent { + #[must_use] pub fn new(data: impl Into, mime_type: impl Into) -> Self { Self { annotations: None, @@ -280,6 +283,7 @@ pub struct TextResourceContents { } impl TextResourceContents { + #[must_use] pub fn new(text: impl Into, uri: impl Into) -> Self { Self { mime_type: None, @@ -326,6 +330,7 @@ pub struct BlobResourceContents { } impl BlobResourceContents { + #[must_use] pub fn new(blob: impl Into, uri: impl Into) -> Self { Self { blob: blob.into(), @@ -380,6 +385,7 @@ pub struct ResourceLink { } impl ResourceLink { + #[must_use] pub fn new(name: impl Into, uri: impl Into) -> Self { Self { annotations: None, diff --git a/src/error.rs b/src/error.rs index 5fb94a16..22a98bff 100644 --- a/src/error.rs +++ b/src/error.rs @@ -54,6 +54,7 @@ impl Error { /// Creates a new error with the given code and message. /// /// The code parameter can be an `ErrorCode` constant or a tuple of (code, message). + #[must_use] pub fn new(code: i32, message: impl Into) -> Self { Error { code: code.into(), @@ -152,6 +153,7 @@ impl Error { /// Converts a standard error into an internal JSON-RPC error. /// /// The error's string representation is included as additional data. + #[must_use] pub fn into_internal_error(err: impl std::error::Error) -> Self { Error::internal_error().data(err.to_string()) } diff --git a/src/ext.rs b/src/ext.rs index ab8c22d0..c89b6b5d 100644 --- a/src/ext.rs +++ b/src/ext.rs @@ -30,6 +30,7 @@ pub struct ExtRequest { } impl ExtRequest { + #[must_use] pub fn new(method: impl Into>, params: Arc) -> Self { Self { method: method.into(), @@ -71,6 +72,7 @@ pub struct ExtNotification { } impl ExtNotification { + #[must_use] pub fn new(method: impl Into>, params: Arc) -> Self { Self { method: method.into(), diff --git a/src/lib.rs b/src/lib.rs index 63805a38..b38e7411 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -100,6 +100,7 @@ use std::{ pub struct SessionId(pub Arc); impl SessionId { + #[must_use] pub fn new(id: impl Into>) -> Self { Self(id.into()) } diff --git a/src/plan.rs b/src/plan.rs index 6d6bc0d1..60d75083 100644 --- a/src/plan.rs +++ b/src/plan.rs @@ -82,6 +82,7 @@ pub struct PlanEntry { } impl PlanEntry { + #[must_use] pub fn new( content: impl Into, priority: PlanEntryPriority, diff --git a/src/rpc.rs b/src/rpc.rs index 5bdfa08d..eb5aeb97 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -72,6 +72,7 @@ pub enum Response { } impl Response { + #[must_use] pub fn new(id: impl Into, result: Result) -> Self { match result { Ok(result) => Self::Result { diff --git a/src/tool_call.rs b/src/tool_call.rs index d8c808b9..5b5ae590 100644 --- a/src/tool_call.rs +++ b/src/tool_call.rs @@ -56,6 +56,7 @@ pub struct ToolCall { } impl ToolCall { + #[must_use] pub fn new(tool_call_id: impl Into, title: impl Into) -> Self { Self { tool_call_id: tool_call_id.into(), @@ -361,6 +362,7 @@ impl From for ToolCallUpdate { pub struct ToolCallId(pub Arc); impl ToolCallId { + #[must_use] pub fn new(id: impl Into>) -> Self { Self(id.into()) } @@ -487,6 +489,7 @@ pub struct Content { } impl Content { + #[must_use] pub fn new(content: impl Into) -> Self { Self { content: content.into(), @@ -571,6 +574,7 @@ pub struct Diff { } impl Diff { + #[must_use] pub fn new(path: impl Into, new_text: impl Into) -> Self { Self { path: path.into(), @@ -624,6 +628,7 @@ pub struct ToolCallLocation { } impl ToolCallLocation { + #[must_use] pub fn new(path: impl Into) -> Self { Self { path: path.into(),