Skip to content

Commit

Permalink
Merge pull request #61 from technocreatives/feature-gated-impls
Browse files Browse the repository at this point in the history
Make feature-gated impls configurable
  • Loading branch information
hulthe authored Nov 27, 2023
2 parents 8cc135f + e104e34 commit 35de328
Show file tree
Hide file tree
Showing 11 changed files with 303 additions and 134 deletions.
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ std = []
can-dbc = "5.0.0"
anyhow = "1.0.68"
heck = "0.4.0"
typed-builder = "0.18.0"

[workspace]
members = [
Expand Down
25 changes: 16 additions & 9 deletions dbc-codegen-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use clap::Parser;
use dbc_codegen::Config;
use std::fs::File;
use std::{path::PathBuf, process::exit};

Expand All @@ -8,8 +9,10 @@ use std::{path::PathBuf, process::exit};
struct Cli {
/// Path to a `.dbc` file
dbc_path: PathBuf,

/// Target directory to write Rust source file(s) to
out_path: PathBuf,

/// Enable debug printing
#[arg(long)]
debug: bool,
Expand Down Expand Up @@ -45,13 +48,17 @@ fn main() {
exit(exitcode::CANTCREAT);
});

dbc_codegen::codegen(&dbc_file_name, &dbc_file, &mut messages_code, args.debug).unwrap_or_else(
|e| {
eprintln!("could not convert `{}`: {}", args.dbc_path.display(), e);
if args.debug {
eprintln!("details: {:?}", e);
}
exit(exitcode::NOINPUT)
},
)
let config = Config::builder()
.dbc_name(&dbc_file_name)
.dbc_content(&dbc_file)
.debug_prints(true)
.build();

dbc_codegen::codegen(config, &mut messages_code).unwrap_or_else(|e| {
eprintln!("could not convert `{}`: {}", args.dbc_path.display(), e);
if args.debug {
eprintln!("details: {:?}", e);
}
exit(exitcode::NOINPUT)
})
}
16 changes: 3 additions & 13 deletions src/includes/errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#[derive(Clone, Copy, PartialEq, Eq)]
#[cfg_attr(any(feature = "debug", feature = "std"), derive(Debug))]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum CanError {
UnknownMessageId(u32),
/// Signal parameter is not within the range
Expand All @@ -18,17 +17,8 @@ pub enum CanError {
},
}

#[cfg(feature = "std")]
use std::error::Error;
#[cfg(feature = "std")]
use std::fmt;

#[cfg(feature = "std")]
impl fmt::Display for CanError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
impl core::fmt::Display for CanError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{:?}", self)
}
}

#[cfg(feature = "std")]
impl Error for CanError {}
Loading

0 comments on commit 35de328

Please sign in to comment.