@@ -3,12 +3,12 @@ use rmcp::{
3
3
schemars:: schema:: { Schema , SchemaObject , SingleOrVec } ,
4
4
serde_json,
5
5
} ;
6
- use std:: { collections:: HashMap , path:: PathBuf } ;
6
+ use std:: { collections:: HashMap , path:: PathBuf , str :: FromStr } ;
7
7
8
- impl TryFrom < & str > for CustomScalarMap {
9
- type Error = ServerError ;
8
+ impl FromStr for CustomScalarMap {
9
+ type Err = ServerError ;
10
10
11
- fn try_from ( string_custom_scalar_file : & str ) -> Result < Self , Self :: Error > {
11
+ fn from_str ( string_custom_scalar_file : & str ) -> Result < Self , Self :: Err > {
12
12
// Parse the string into an initial map of serde_json::Values
13
13
let parsed_custom_scalar_file: serde_json:: Map < String , serde_json:: Value > =
14
14
serde_json:: from_str ( string_custom_scalar_file)
@@ -44,7 +44,7 @@ impl TryFrom<&PathBuf> for CustomScalarMap {
44
44
let custom_scalars_config_path = file_path_buf. as_path ( ) ;
45
45
tracing:: info!( custom_scalars_config=?custom_scalars_config_path, "Loading custom_scalars_config" ) ;
46
46
let string_custom_scalar_file = std:: fs:: read_to_string ( custom_scalars_config_path) ?;
47
- CustomScalarMap :: try_from ( string_custom_scalar_file. as_str ( ) )
47
+ CustomScalarMap :: from_str ( string_custom_scalar_file. as_str ( ) )
48
48
}
49
49
}
50
50
@@ -79,7 +79,10 @@ fn has_invalid_schema(schema: &Schema) -> bool {
79
79
80
80
#[ cfg( test) ]
81
81
mod tests {
82
- use std:: collections:: { BTreeMap , HashMap } ;
82
+ use std:: {
83
+ collections:: { BTreeMap , HashMap } ,
84
+ str:: FromStr ,
85
+ } ;
83
86
84
87
use rmcp:: schemars:: schema:: {
85
88
InstanceType , ObjectValidation , Schema , SchemaObject , SingleOrVec ,
@@ -89,7 +92,7 @@ mod tests {
89
92
90
93
#[ test]
91
94
fn empty_file ( ) {
92
- let result = CustomScalarMap :: try_from ( "" ) . err ( ) . unwrap ( ) ;
95
+ let result = CustomScalarMap :: from_str ( "" ) . err ( ) . unwrap ( ) ;
93
96
94
97
insta:: assert_debug_snapshot!( result, @r###"
95
98
CustomScalarConfig(
@@ -100,7 +103,7 @@ mod tests {
100
103
101
104
#[ test]
102
105
fn only_spaces ( ) {
103
- let result = CustomScalarMap :: try_from ( " " ) . err ( ) . unwrap ( ) ;
106
+ let result = CustomScalarMap :: from_str ( " " ) . err ( ) . unwrap ( ) ;
104
107
105
108
insta:: assert_debug_snapshot!( result, @r###"
106
109
CustomScalarConfig(
@@ -111,7 +114,7 @@ mod tests {
111
114
112
115
#[ test]
113
116
fn invalid_json ( ) {
114
- let result = CustomScalarMap :: try_from ( "Hello: }" ) . err ( ) . unwrap ( ) ;
117
+ let result = CustomScalarMap :: from_str ( "Hello: }" ) . err ( ) . unwrap ( ) ;
115
118
116
119
insta:: assert_debug_snapshot!( result, @r###"
117
120
CustomScalarConfig(
@@ -122,7 +125,7 @@ mod tests {
122
125
123
126
#[ test]
124
127
fn invalid_simple_schema ( ) {
125
- let result = CustomScalarMap :: try_from (
128
+ let result = CustomScalarMap :: from_str (
126
129
r###"{
127
130
"custom": {
128
131
"test": true
@@ -143,7 +146,7 @@ mod tests {
143
146
144
147
#[ test]
145
148
fn invalid_complex_schema ( ) {
146
- let result = CustomScalarMap :: try_from (
149
+ let result = CustomScalarMap :: from_str (
147
150
r###"{
148
151
"custom": {
149
152
"type": "object",
@@ -174,7 +177,7 @@ mod tests {
174
177
175
178
#[ test]
176
179
fn valid_schema ( ) {
177
- let result = CustomScalarMap :: try_from (
180
+ let result = CustomScalarMap :: from_str (
178
181
r###"
179
182
{
180
183
"simple": {
0 commit comments