@@ -81,29 +81,29 @@ impl DefinitionIdentifier {
8181 } ) ,
8282 }
8383 }
84+
85+ pub fn serialized ( & self ) -> String {
86+ match self {
87+ DefinitionIdentifier :: ProtoNode ( id) => {
88+ format ! ( "Proto Node:{}" , id. as_str( ) )
89+ }
90+ DefinitionIdentifier :: Network ( data) => {
91+ format ! ( "Network:{}" , data)
92+ }
93+ }
94+ }
8495}
8596
8697impl From < Value > for DefinitionIdentifier {
8798 fn from ( value : Value ) -> Self {
88- match value {
89- Value :: Object ( mut map) => {
90- let ty = map. remove ( "type" ) . unwrap ( ) . as_str ( ) . unwrap ( ) . to_owned ( ) ;
99+ let s = value. as_str ( ) . expect ( "DefinitionIdentifier value must be a string" ) ;
91100
92- match ty. as_ref ( ) {
93- "Network" => {
94- let data = map. remove ( "data" ) . unwrap ( ) . as_str ( ) . unwrap ( ) . to_owned ( ) ;
95- DefinitionIdentifier :: Network ( data)
96- }
97- "ProtoNode" => {
98- let value = map. remove ( "data" ) . unwrap ( ) ;
99- let proto: ProtoNodeIdentifier = serde_json:: from_value ( value) . unwrap ( ) ;
100- DefinitionIdentifier :: ProtoNode ( proto)
101- }
102- _ => panic ! ( "Unknown `DefinitionIdentifier` type: {:?}" , ty) ,
103- }
104- }
101+ let ( ty, data) = s. split_once ( ':' ) . expect ( "Invalid DefinitionIdentifier key format" ) ;
105102
106- _ => panic ! ( "Expected a JSON object to convert to `DefinitionIdentifier`" ) ,
103+ match ty {
104+ "Proto Node" => DefinitionIdentifier :: ProtoNode ( ProtoNodeIdentifier :: with_owned_string ( data. to_string ( ) ) ) ,
105+ "Network" => DefinitionIdentifier :: Network ( data. to_string ( ) ) ,
106+ other => panic ! ( "Unknown DefinitionIdentifier type: {other}" ) ,
107107 }
108108 }
109109}
@@ -2682,7 +2682,7 @@ pub fn collect_node_types() -> Vec<FrontendNodeType> {
26822682 name = identifier. implementation_name_from_identifier ( )
26832683 }
26842684 FrontendNodeType {
2685- identifier : identifier. clone ( ) ,
2685+ identifier : identifier. serialized ( ) ,
26862686 name,
26872687 category : definition. category . to_string ( ) ,
26882688 input_types,
@@ -2691,10 +2691,15 @@ pub fn collect_node_types() -> Vec<FrontendNodeType> {
26912691 . collect ( )
26922692}
26932693
2694- pub fn collect_node_descriptions ( ) -> Vec < ( DefinitionIdentifier , String ) > {
2694+ pub fn collect_node_descriptions ( ) -> Vec < ( String , String ) > {
26952695 DOCUMENT_NODE_TYPES
26962696 . iter ( )
2697- . map ( |( identifier, definition) | ( identifier. clone ( ) , if definition. description != "TODO" { definition. description . to_string ( ) } else { String :: new ( ) } ) )
2697+ . map ( |( identifier, definition) | {
2698+ (
2699+ identifier. serialized ( ) ,
2700+ if definition. description != "TODO" { definition. description . to_string ( ) } else { String :: new ( ) } ,
2701+ )
2702+ } )
26982703 . collect ( )
26992704}
27002705
0 commit comments