Skip to content

Commit 477531b

Browse files
committed
Segregate device specific generation to its own struct
1 parent 9e56759 commit 477531b

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/lib.rs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,12 +439,21 @@ mod generate;
439439
mod util;
440440

441441
pub use util::Target;
442-
use util::build_rs;
443442

444443
pub struct Generation {
445444
pub lib_rs: String,
445+
pub device_specific: Option<DeviceSpecific>,
446+
447+
// Reserve the right to add more fields to this struct
448+
_extensible: (),
449+
}
450+
451+
pub struct DeviceSpecific {
446452
pub device_x: String,
447453
pub build_rs: String,
454+
455+
// Reserve the right to add more fields to this struct
456+
_extensible: (),
448457
}
449458

450459
type Result<T> = std::result::Result<T, SvdError>;
@@ -470,11 +479,23 @@ pub fn generate(xml: &str, target: &Target, nightly: bool) -> Result<Generation>
470479
quote! {
471480
#(#items)*
472481
}
473-
).or(Err(SvdError::Fmt))?;
482+
)
483+
.or(Err(SvdError::Fmt))?;
484+
485+
let device_specific = if device_x.is_empty() {
486+
None
487+
} else {
488+
Some(DeviceSpecific {
489+
device_x: device_x,
490+
build_rs: util::build_rs().to_string(),
491+
_extensible: (),
492+
})
493+
};
494+
474495
Ok(Generation {
475496
lib_rs: lib_rs,
476-
device_x: device_x,
477-
build_rs: build_rs().to_string(),
497+
device_specific: device_specific,
498+
_extensible: (),
478499
})
479500
}
480501

0 commit comments

Comments
 (0)