11use crate :: builder:: DictionaryBuilder ;
22use crate :: component:: { ComponentData , FixmlComponentAttributes } ;
3+ use crate :: error:: { ParseError , ParseResult } ;
34use crate :: message_definition:: MessageData ;
45use crate :: string:: SmartString ;
56use crate :: {
@@ -29,7 +30,7 @@ impl<'a> QuickFixReader<'a> {
2930 if child. is_element ( ) {
3031 let name = child
3132 . attribute ( "name" )
32- . ok_or ( ParseDictionaryError :: InvalidFormat ) ?
33+ . ok_or ( ParseError :: InvalidFormat ) ?
3334 . to_string ( ) ;
3435 import_component ( & mut reader. builder , child, & name) ?;
3536 }
@@ -61,23 +62,17 @@ impl<'a> QuickFixReader<'a> {
6162 let find_tagged_child = |tag : & str | {
6263 root. children ( )
6364 . find ( |n| n. has_tag_name ( tag) )
64- . ok_or_else ( || ParseDictionaryError :: InvalidData ( format ! ( "<{tag}> tag not found" ) ) )
65+ . ok_or_else ( || ParseError :: InvalidData ( format ! ( "<{tag}> tag not found" ) ) )
6566 } ;
6667 let version_type = root
6768 . attribute ( "type" )
68- . ok_or ( ParseDictionaryError :: InvalidData (
69- "No version attribute." . to_string ( ) ,
70- ) ) ?;
71- let version_major = root
72- . attribute ( "major" )
73- . ok_or ( ParseDictionaryError :: InvalidData (
74- "No major version attribute." . to_string ( ) ,
75- ) ) ?;
76- let version_minor = root
77- . attribute ( "minor" )
78- . ok_or ( ParseDictionaryError :: InvalidData (
79- "No minor version attribute." . to_string ( ) ,
80- ) ) ?;
69+ . ok_or ( ParseError :: InvalidData ( "No version attribute." . to_string ( ) ) ) ?;
70+ let version_major = root. attribute ( "major" ) . ok_or ( ParseError :: InvalidData (
71+ "No major version attribute." . to_string ( ) ,
72+ ) ) ?;
73+ let version_minor = root. attribute ( "minor" ) . ok_or ( ParseError :: InvalidData (
74+ "No minor version attribute." . to_string ( ) ,
75+ ) ) ?;
8176 let version_sp = root. attribute ( "servicepack" ) . unwrap_or ( "0" ) ;
8277 let version = format ! (
8378 "{}.{}.{}{}" ,
@@ -104,19 +99,19 @@ impl<'a> QuickFixReader<'a> {
10499
105100fn import_field ( builder : & mut DictionaryBuilder , node : roxmltree:: Node ) -> ParseResult < ( ) > {
106101 if node. tag_name ( ) . name ( ) != "field" {
107- return Err ( ParseDictionaryError :: InvalidFormat ) ;
102+ return Err ( ParseError :: InvalidFormat ) ;
108103 }
109104 let data_type_name = import_datatype ( builder, node) ;
110105 let value_restrictions = value_restrictions_from_node ( node, data_type_name. clone ( ) ) ;
111106 let name = node
112107 . attribute ( "name" )
113- . ok_or ( ParseDictionaryError :: InvalidFormat ) ?
108+ . ok_or ( ParseError :: InvalidFormat ) ?
114109 . into ( ) ;
115110 let tag = node
116111 . attribute ( "number" )
117- . ok_or ( ParseDictionaryError :: InvalidFormat ) ?
112+ . ok_or ( ParseError :: InvalidFormat ) ?
118113 . parse ( )
119- . map_err ( |_| ParseDictionaryError :: InvalidFormat ) ?;
114+ . map_err ( |_| ParseError :: InvalidFormat ) ?;
120115 let field = FieldData {
121116 name,
122117 tag,
@@ -142,11 +137,11 @@ fn import_message(builder: &mut DictionaryBuilder, node: roxmltree::Node) -> Par
142137 let message = MessageData {
143138 name : node
144139 . attribute ( "name" )
145- . ok_or ( ParseDictionaryError :: InvalidFormat ) ?
140+ . ok_or ( ParseError :: InvalidFormat ) ?
146141 . into ( ) ,
147142 msg_type : node
148143 . attribute ( "msgtype" )
149- . ok_or ( ParseDictionaryError :: InvalidFormat ) ?
144+ . ok_or ( ParseError :: InvalidFormat ) ?
150145 . into ( ) ,
151146 component_id : 0 ,
152147 layout_items,
@@ -289,7 +284,7 @@ fn import_layout_item(
289284 }
290285 }
291286 _ => {
292- return Err ( ParseDictionaryError :: InvalidFormat ) ;
287+ return Err ( ParseError :: InvalidFormat ) ;
293288 }
294289 } ;
295290 let item = LayoutItemData { required, kind } ;
@@ -306,13 +301,3 @@ fn panic_missing_tag_in_element(elem: roxmltree::Node, tag: &str) -> ! {
306301 . unwrap_or( "Error retrieving element text" )
307302 ) ;
308303}
309-
310- type ParseError = ParseDictionaryError ;
311- type ParseResult < T > = Result < T , ParseError > ;
312-
313- /// The error type that can arise when decoding a QuickFIX Dictionary.
314- #[ derive( Clone , Debug ) ]
315- pub enum ParseDictionaryError {
316- InvalidFormat ,
317- InvalidData ( String ) ,
318- }
0 commit comments