Skip to content

Commit

Permalink
add custom error for priority and helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jannes Brands committed Jan 27, 2024
1 parent 4b15403 commit aa657d7
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/j1939/priority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use crate::j1939::DriverOpenError;
#[derive(Debug)]
struct ParsePriorityError(u8);

//TODO!: custom parse priority error

impl std::fmt::Display for ParsePriorityError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
Expand Down Expand Up @@ -34,6 +32,21 @@ impl Priority {
pub const HIGHEST: Priority = Priority::Zero;
pub const DEFAULT: Priority = Priority::Six;
pub const LOWEST: Priority = Priority::Seven;

#[inline]
pub fn is_highest(&self) -> bool {
self == Self::HIGHEST
}

#[inline]
pub fn is_default(&self) -> bool {
self == Self::DEFAULT
}

#[inline]
pub fn is_lowest(&self) -> bool {
self == Self::LOWEST
}
}

impl TryFrom<u8> for Priority {
Expand Down

0 comments on commit aa657d7

Please sign in to comment.