Skip to content

Commit

Permalink
Implement Debug for motion_control::Error
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Feb 26, 2021
1 parent b97e867 commit e030248
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/motion_control.rs
Expand Up @@ -4,6 +4,7 @@

use core::{
convert::{TryFrom, TryInto},
fmt,
task::Poll,
};

Expand Down Expand Up @@ -202,6 +203,51 @@ where
StepDelay(Timer::Error),
}

// Can't `#[derive(Debug)]`, as that can't generate the required trait bounds.
impl<Driver, Timer, Profile> fmt::Debug for Error<Driver, Timer, Profile>
where
Driver: SetDirection + Step,
Timer: timer::CountDown,
Profile: MotionProfile,
Timer::Time: TryFrom<Nanoseconds>,
Profile::Delay: TryInto<Nanoseconds>,
<Driver as SetDirection>::Error: fmt::Debug,
<Driver as Step>::Error: fmt::Debug,
Timer::Error: fmt::Debug,
Timer::Time: fmt::Debug,
<Timer::Time as TryFrom<Nanoseconds>>::Error: fmt::Debug,
Profile::Delay: fmt::Debug,
<Profile::Delay as TryInto<Nanoseconds>>::Error: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::SetDirection(err) => {
write!(f, "SetDirection(")?;
err.fmt(f)?;
write!(f, ")")?;
}
Self::Step(err) => {
write!(f, "Step(")?;
err.fmt(f)?;
write!(f, ")")?;
}
Self::TimeConversion(err) => {
write!(f, "TimeConversion(")?;
err.fmt(f)?;
write!(f, ")")?;
}
Self::StepDelay(err) => {
write!(f, "StepDelay(")?;
err.fmt(f)?;
write!(f, ")")?;
}
}

Ok(())
}
}

#[derive(Debug)]
/// An error occurred while converting between time formats
pub enum TimeConversionError<
Time: TryFrom<Nanoseconds>,
Expand Down

0 comments on commit e030248

Please sign in to comment.