@@ -91,18 +91,34 @@ pub struct Device {
9191 pub peripherals : Vec < Peripheral > ,
9292
9393 /// 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" ) ) ]
9595 pub xmlns_xs : String ,
9696
9797 /// 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+ ) ]
99102 pub no_namespace_schema_location : String ,
100103
101104 /// 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" ) ) ]
103106 pub schema_version : String ,
104107}
105108
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+
106122/// Builder for [`Device`]
107123#[ derive( Clone , Debug , Default ) ]
108124pub struct DeviceBuilder {
@@ -237,7 +253,7 @@ impl DeviceBuilder {
237253 }
238254 /// Validate and build a [`Device`].
239255 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 ) ;
241257 let mut device = Device {
242258 vendor : self . vendor ,
243259 vendor_id : self . vendor_id ,
@@ -281,12 +297,10 @@ impl DeviceBuilder {
281297 peripherals : self
282298 . peripherals
283299 . 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) ,
290304 schema_version,
291305 } ;
292306 if !lvl. is_disabled ( ) {
0 commit comments