@@ -91,18 +91,34 @@ pub struct Device {
91
91
pub peripherals : Vec < Peripheral > ,
92
92
93
93
/// Specify the underlying XML schema to which the CMSIS-SVD schema is compliant.
94
- #[ cfg_attr( feature = "serde" , serde( skip) ) ]
94
+ #[ cfg_attr( feature = "serde" , serde( skip, default = "default_xmlns_xs" ) ) ]
95
95
pub xmlns_xs : String ,
96
96
97
97
/// Specify the file path and file name of the CMSIS-SVD Schema
98
- #[ cfg_attr( feature = "serde" , serde( skip) ) ]
98
+ #[ cfg_attr(
99
+ feature = "serde" ,
100
+ serde( skip, default = "default_no_namespace_schema_location" )
101
+ ) ]
99
102
pub no_namespace_schema_location : String ,
100
103
101
104
/// Specify the compliant CMSIS-SVD schema version
102
- #[ cfg_attr( feature = "serde" , serde( skip) ) ]
105
+ #[ cfg_attr( feature = "serde" , serde( skip, default = "default_schema_version" ) ) ]
103
106
pub schema_version : String ,
104
107
}
105
108
109
+ fn default_xmlns_xs ( ) -> String {
110
+ "http://www.w3.org/2001/XMLSchema-instance" . into ( )
111
+ }
112
+ fn default_no_namespace_schema_location ( ) -> String {
113
+ format ! (
114
+ "CMSIS-SVD_Schema_{}.xsd" ,
115
+ default_schema_version( ) . replace( '.' , "_" )
116
+ )
117
+ }
118
+ fn default_schema_version ( ) -> String {
119
+ "1.1" . into ( )
120
+ }
121
+
106
122
/// Builder for [`Device`]
107
123
#[ derive( Clone , Debug , Default ) ]
108
124
pub struct DeviceBuilder {
@@ -237,7 +253,7 @@ impl DeviceBuilder {
237
253
}
238
254
/// Validate and build a [`Device`].
239
255
pub fn build ( self , lvl : ValidateLevel ) -> Result < Device , SvdError > {
240
- let schema_version = self . schema_version . unwrap_or_else ( || "1.1" . into ( ) ) ;
256
+ let schema_version = self . schema_version . unwrap_or_else ( default_schema_version ) ;
241
257
let mut device = Device {
242
258
vendor : self . vendor ,
243
259
vendor_id : self . vendor_id ,
@@ -281,12 +297,10 @@ impl DeviceBuilder {
281
297
peripherals : self
282
298
. peripherals
283
299
. ok_or_else ( || BuildError :: Uninitialized ( "peripherals" . to_string ( ) ) ) ?,
284
- xmlns_xs : self
285
- . xmlns_xs
286
- . unwrap_or_else ( || "http://www.w3.org/2001/XMLSchema-instance" . into ( ) ) ,
287
- no_namespace_schema_location : self . no_namespace_schema_location . unwrap_or_else ( || {
288
- format ! ( "CMSIS-SVD_Schema_{}.xsd" , schema_version. replace( "." , "_" ) )
289
- } ) ,
300
+ xmlns_xs : self . xmlns_xs . unwrap_or_else ( default_xmlns_xs) ,
301
+ no_namespace_schema_location : self
302
+ . no_namespace_schema_location
303
+ . unwrap_or_else ( default_no_namespace_schema_location) ,
290
304
schema_version,
291
305
} ;
292
306
if !lvl. is_disabled ( ) {
0 commit comments