Skip to content
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

Very repetitious output when deriving enumeratedValues #115

Closed
roysmeding opened this issue Jun 11, 2017 · 2 comments
Closed

Very repetitious output when deriving enumeratedValues #115

roysmeding opened this issue Jun 11, 2017 · 2 comments

Comments

@roysmeding
Copy link

As I've said elsewhere, I'm working on adding enumeratedValues to the SVD for the MCU I'm using. Since there are a lot of fields that use the same enumerations, I'm reusing them using e.g. <enumeratedValues derivedFrom="GPIOA.MODER.MODER15.MODE" /> in each field.

However, when inspecting the output, I noticed this results in a lot of duplicated code. Most of it seems to be due to the separate write proxies for each field, with each proxy defining all the variant methods, despite their implementation being the exact same each time.

This isn't a huge problem, and I understand why the separate write proxy objects are necessary (each field has a different offset), but it seems like there should be a less boilerplate-y way to accomplish the same thing? The first thing that comes to mind is generics with numerical arguments, but those aren't a part of Rust yet, unfortunately. I'm fairly new to Rust, though, so maybe someone has a better idea?

Some of this would be ameliorated by #44 but that wouldn't stop the duplication entirely.

@japaric
Copy link
Member

japaric commented Jun 20, 2017

The first thing that comes to mind is generics with numerical arguments

I don't think generics are required. The field offset could be stored as a field in the proxy object:

struct CommonFieldW<'a> {
    w: &'a mut W,
    offset: u8,
}

// instead of FieldAW use CommonFieldW { w, offset: 0 }
// instead of FieldBW use CommonFieldW { w, offset: 1 }
// instead of FieldCW use CommonFieldW { w, offset: 2 }
// ...

This was referenced Jul 25, 2019
@burrbull
Copy link
Member

burrbull commented Nov 7, 2022

Closing as implemented. Open new issue if you find it.

@burrbull burrbull closed this as completed Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants