-
Notifications
You must be signed in to change notification settings - Fork 59
Add a function to produce merged peripheral when derivedFrom is used. #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I'm not sure about having this in this crate. What reasons are there for it being in this crate instead of having it as a function in |
Could just as well be there, if this crate is just to be tasked with parsing. However, if someone wanted to write |
@@ -178,6 +178,23 @@ pub struct Peripheral { | |||
} | |||
|
|||
impl Peripheral { | |||
pub fn derive_from(&self, other: &Peripheral) -> Peripheral { | |||
let mut derived = self.clone(); | |||
if derived.group_name.is_none() && other.group_name.is_some() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor nit: the conditionals here don't need to check other.XXX
. If they're is_none
then the derived
value will get assigned to None
anyway. It just feels a little less repetitive:
if derived.group_name.is_none() {
derived.group_name = other.group_name.clone();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I second this. I'll merge this when this has been fixed.
I'm also in favor of moving this function into rust-embedded/svd2rust#190 for the sake of having fewer things to review and merge :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've talked to @ryankurte and now this makes more sense to have in this crate. Only thing that needs to change is what @wez already adressed
@@ -178,6 +178,23 @@ pub struct Peripheral { | |||
} | |||
|
|||
impl Peripheral { | |||
pub fn derive_from(&self, other: &Peripheral) -> Peripheral { | |||
let mut derived = self.clone(); | |||
if derived.group_name.is_none() && other.group_name.is_some() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I second this. I'll merge this when this has been fixed.
@Emilgardis —Thanks for the patience, and for fixing up my awkward style! The fixed version has lines like:
Shouldn't it be:
To avoid calling |
Added a function to make a new peripheral by overlaying the peripheral over its derivedFrom peripheral. I read the spec that it is a shallow copy, but I could be wrong. This may be part of #21.
With this change, and another one that I have for svd2rust, svd2rust can generate peripherals with derivedFrom. I could have put this function over there, but I think the way overlaying is done is a part of the SVD spec, and not part of the particular svd2rust implementation, so it makes more sense for me to put it here.