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

Implement common traits #111

Open
3 of 10 tasks
MarcoIeni opened this issue Apr 16, 2020 · 2 comments
Open
3 of 10 tasks

Implement common traits #111

MarcoIeni opened this issue Apr 16, 2020 · 2 comments

Comments

@MarcoIeni
Copy link
Contributor

MarcoIeni commented Apr 16, 2020

from the api guidelines:
https://rust-lang.github.io/api-guidelines/interoperability.html

Device should implement the following common traits:

  • Copy
  • Clone
  • Eq
  • PartialEq
  • Ord
  • PartialOrd
  • Hash
  • Debug
  • Display
  • Default
@cr1901
Copy link

cr1901 commented Apr 20, 2020

@MarcoIeni I ran headfirst into this issue as well. My workaround for now is the following:

// Newtype to implement PartialEq on svd::Device without needing
// to fork the crate.
#[derive(Debug)]
struct DeviceWrapper(svd::Device);

impl PartialEq<DeviceWrapper> for DeviceWrapper {
    fn eq(&self, other: &DeviceWrapper) -> bool {
        let dev_self : &svd::Device = &self.0;
        let other_self : &svd::Device = &self.0;

        (dev_self.name == other_self.name) &&
        (dev_self.version == other_self.version) &&
        (dev_self.description == other_self.description) &&
        (dev_self.address_unit_bits == other_self.address_unit_bits) &&
        (dev_self.width == other_self.width) &&
        (dev_self.cpu == other_self.cpu) &&
        (dev_self.peripherals == other_self.peripherals) &&
        (dev_self.default_register_properties == other_self.default_register_properties)
    }
}

...
match svd::parse(&out_svd) {
        Ok(parsed) => { assert_eq!(DeviceWrapper(svd_dev), DeviceWrapper(parsed)); },
        Err(e) => {
            eprintln!("Parsing output file {} during round-trip test failed", out_svd);
            return;
        }
    }

Unfortunately, this is not sufficient for my needs for msp430_svd and trying to remove the outdated local copy of svd-parser we have.

It's not possible for me to actually construct peripheral instances at all because the _extensible: (), field is private. I believe this would be solved if a Default implementation was derived, combined with struct update syntax (..)?

Perhaps provide it behind a feature gate?

@MarcoIeni
Copy link
Contributor Author

Wow, thank you for the workaround, but I would prefer a proper fix in this repo

It's not possible for me to actually construct peripheral instances at all

See #101

bors bot added a commit that referenced this issue May 1, 2020
117: derive PartialEq for Device r=therealprof a=MarcoIeni

Partially solves #111

Co-authored-by: MarcoIeni <[email protected]>
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

2 participants