Skip to content

Commit

Permalink
DLT SomeIP: Check for constant boolean directly
Browse files Browse the repository at this point in the history
* Check for constant bool `CAN_ERROR` directly method without the need
  to an extra method to access it.
* Remove the unneeded inline method
  • Loading branch information
AmmarAbouZor committed Aug 31, 2024
1 parent 46ba96e commit c6a7b8f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
7 changes: 1 addition & 6 deletions application/apps/indexer/parsers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,10 @@ where
}

pub trait LogMessage: Serialize {
//TODO AAZ: Measure this an remove if rust already optimize the code without it.
/// Indicates that parsing this struct to text can error.
const CAN_ERROR: bool;

//TODO AAZ: Measure this an remove if rust already optimize the code without it.
#[inline(always)]
fn can_error(&self) -> bool {
<Self as LogMessage>::CAN_ERROR
}

/// Serializes a message directly into a Writer
/// returns the size of the serialized message
fn to_writer<W: Write>(&self, writer: &mut W) -> Result<usize, std::io::Error>;
Expand Down
4 changes: 2 additions & 2 deletions application/apps/indexer/session/src/parse_err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ impl ParseErrorReslover {
/// Get the text message of [`LogMessage`], resolving parse text errors if possible,
/// TODO: Otherwise it should save the error to the faulty messages store, which need to be
/// implemented as well :)
pub fn get_log_text(item: impl LogMessage, err_resolver: &mut ParseErrorReslover) -> String {
pub fn get_log_text<T: LogMessage>(item: T, err_resolver: &mut ParseErrorReslover) -> String {
let text_res = item.to_text();
if item.can_error() {
if T::CAN_ERROR {
let mut msg = text_res.msg;
if let Some(err_info) = text_res.error {
match err_resolver.resolve_err(&err_info) {
Expand Down

0 comments on commit c6a7b8f

Please sign in to comment.