@@ -80,29 +80,23 @@ impl DefinitionIdentifier {
8080 } ) ,
8181 }
8282 }
83+
84+ pub fn serialized ( & self ) -> String {
85+ match self {
86+ DefinitionIdentifier :: ProtoNode ( id) => format ! ( "PROTONODE:{}" , id. as_str( ) ) ,
87+ DefinitionIdentifier :: Network ( data) => format ! ( "NETWORK:{}" , data) ,
88+ }
89+ }
8390}
8491
8592impl From < Value > for DefinitionIdentifier {
8693 fn from ( value : Value ) -> Self {
87- match value {
88- Value :: Object ( mut map) => {
89- let ty = map. remove ( "type" ) . unwrap ( ) . as_str ( ) . unwrap ( ) . to_owned ( ) ;
94+ let s = value. as_str ( ) . expect ( "DefinitionIdentifier value must be a string" ) ;
9095
91- match ty. as_ref ( ) {
92- "Network" => {
93- let data = map. remove ( "data" ) . unwrap ( ) . as_str ( ) . unwrap ( ) . to_owned ( ) ;
94- DefinitionIdentifier :: Network ( data)
95- }
96- "ProtoNode" => {
97- let value = map. remove ( "data" ) . unwrap ( ) ;
98- let proto: ProtoNodeIdentifier = serde_json:: from_value ( value) . unwrap ( ) ;
99- DefinitionIdentifier :: ProtoNode ( proto)
100- }
101- _ => panic ! ( "Unknown `DefinitionIdentifier` type: {:?}" , ty) ,
102- }
103- }
104-
105- _ => panic ! ( "Expected a JSON object to convert to `DefinitionIdentifier`" ) ,
96+ match s. split_once ( ':' ) {
97+ Some ( ( "PROTONODE" , data) ) => DefinitionIdentifier :: ProtoNode ( ProtoNodeIdentifier :: with_owned_string ( data. to_string ( ) ) ) ,
98+ Some ( ( "NETWORK" , data) ) => DefinitionIdentifier :: Network ( data. to_string ( ) ) ,
99+ other => panic ! ( "Unknown `DefinitionIdentifier` type. Found `{other:?}`." ) ,
106100 }
107101 }
108102}
@@ -2621,7 +2615,7 @@ pub fn collect_node_types() -> Vec<FrontendNodeType> {
26212615 name = identifier. implementation_name_from_identifier ( )
26222616 }
26232617 FrontendNodeType {
2624- identifier : identifier. clone ( ) ,
2618+ identifier : identifier. serialized ( ) ,
26252619 name,
26262620 category : definition. category . to_string ( ) ,
26272621 input_types,
@@ -2630,10 +2624,15 @@ pub fn collect_node_types() -> Vec<FrontendNodeType> {
26302624 . collect ( )
26312625}
26322626
2633- pub fn collect_node_descriptions ( ) -> Vec < ( DefinitionIdentifier , String ) > {
2627+ pub fn collect_node_descriptions ( ) -> Vec < ( String , String ) > {
26342628 DOCUMENT_NODE_TYPES
26352629 . iter ( )
2636- . map ( |( identifier, definition) | ( identifier. clone ( ) , if definition. description != "TODO" { definition. description . to_string ( ) } else { String :: new ( ) } ) )
2630+ . map ( |( identifier, definition) | {
2631+ (
2632+ identifier. serialized ( ) ,
2633+ if definition. description != "TODO" { definition. description . to_string ( ) } else { String :: new ( ) } ,
2634+ )
2635+ } )
26372636 . collect ( )
26382637}
26392638
0 commit comments