@@ -104,6 +104,26 @@ pub fn error_to_json(error: &anyhow::Error, action_identifier: &str) -> serde_js
104
104
} )
105
105
}
106
106
107
+ pub fn string_result_to_json (
108
+ result : & Result < String , & anyhow:: Error > ,
109
+ action_identifier : & str ,
110
+ ) -> serde_json:: Value {
111
+ match result {
112
+ Ok ( value) => json ! ( { "result" : value } ) ,
113
+ Err ( e) => error_to_json ( e, action_identifier) ,
114
+ }
115
+ }
116
+
117
+ pub fn string_vec_result_to_json (
118
+ result : & Result < Vec < String > , & anyhow:: Error > ,
119
+ action_identifier : & str ,
120
+ ) -> serde_json:: Value {
121
+ match result {
122
+ Ok ( values) => json ! ( { "result" : values } ) ,
123
+ Err ( e) => error_to_json ( e, action_identifier) ,
124
+ }
125
+ }
126
+
107
127
pub fn result_to_json < T : serde:: Serialize > (
108
128
result : & Result < T , anyhow:: Error > ,
109
129
action_identifier : & str ,
@@ -141,11 +161,15 @@ impl ToolResult for Result<StackId, anyhow::Error> {
141
161
142
162
impl ToolResult for Result < gix:: ObjectId , anyhow:: Error > {
143
163
fn to_json ( & self , action_identifier : & str ) -> serde_json:: Value {
144
- result_to_json ( self , action_identifier, "gix::ObjectId" )
164
+ let result = self . as_ref ( ) . map ( |id| id. to_string ( ) ) ;
165
+ string_result_to_json ( & result, action_identifier)
145
166
}
146
167
}
147
168
impl ToolResult for Result < Vec < gix:: ObjectId > , anyhow:: Error > {
148
169
fn to_json ( & self , action_identifier : & str ) -> serde_json:: Value {
149
- result_to_json ( self , action_identifier, "Vec<gix::ObjectId>" )
170
+ let result = self
171
+ . as_ref ( )
172
+ . map ( |ids| ids. iter ( ) . map ( |id| id. to_string ( ) ) . collect :: < Vec < String > > ( ) ) ;
173
+ string_vec_result_to_json ( & result, action_identifier)
150
174
}
151
175
}
0 commit comments