1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
7#[serde(untagged)]
8pub enum ToolResult {
9 Success { success: bool, content: String },
11 Error { success: bool, error: String },
13}
14
15impl ToolResult {
16 pub fn success(content: impl Into<String>) -> Self {
18 Self::Success {
19 success: true,
20 content: content.into(),
21 }
22 }
23
24 pub fn error(message: impl Into<String>) -> Self {
26 Self::Error {
27 success: false,
28 error: message.into(),
29 }
30 }
31
32 pub fn is_success(&self) -> bool {
34 matches!(self, Self::Success { .. })
35 }
36
37 pub fn content(&self) -> Option<&str> {
39 match self {
40 Self::Success { content, .. } => Some(content),
41 Self::Error { .. } => None,
42 }
43 }
44
45 pub fn error_message(&self) -> Option<&str> {
47 match self {
48 Self::Success { .. } => None,
49 Self::Error { error, .. } => Some(error),
50 }
51 }
52}