technocreatives / dbc-codegen

Generate Rust structs for messages from a dbc (CAN bus definition) file.
Apache License 2.0
46 stars 27 forks source link

Create separate crate for helper types and external dependencies #84

Open scootermon opened 2 weeks ago

scootermon commented 2 weeks ago

The main issue I want to address is that the generated code currently contains the CanError enum. I have multiple DBC files for different can buses that I would like to abstract in a single crate, but having multiple equal but distinct CanError types makes this really annoying.

To solve this I think it would be good to introduce a separate runtime crate. This crate can then hold common types and also re-export the additional dependencies used by the extra code. The latter can be done through a hidden module like:

#[doc(hidden)]
mod __priv {
  pub use bitvec;
  // [...]
}

I'm happy to work on an initial implementation if we're happy with this approach.

killercup commented 2 weeks ago

What do you think of #35? I'd be happy to merge some big refactors if you can motivate them :)

scootermon commented 2 weeks ago

35 is exactly the use case I wanted to use this crate for initially. I have a repository of dbc files and I wanted to just iterate over all of them, generate a crate for each one, and publish them to an internal registry.