added result return to get_switch_state #30

Merged
muellerr merged 2 commits from power_abstraction_result_return into power_abstractions 2023-02-07 16:04:40 +01:00
Showing only changes of commit ae8718ed6a - Show all commits

View File

@ -49,11 +49,8 @@ pub trait PowerSwitcher {
/// Retrieve the switch state
fn get_switch_state(&mut self, switch_id: SwitchId) -> Result<SwitchState, Self::Error>;
fn get_is_switch_on(&mut self, switch_id: SwitchId) -> Result<bool, ()> {
match self.get_switch_state(switch_id) {
Ok(switch_state) => { Ok(switch_state == SwitchState::On) }
Err(_) => { Err(()) }
}
fn get_is_switch_on(&mut self, switch_id: SwitchId) -> Result<bool, Self::Error> {
lkoester marked this conversation as resolved Outdated

I think Result<bool, Self::Error> can be returned here by writing self.get_switch_state(..)? == SwitchState::On

I think `Result<bool, Self::Error>` can be returned here by writing `self.get_switch_state(..)? == SwitchState::On`
Ok(self.get_switch_state(switch_id)? == SwitchState::On)
}
/// The maximum delay it will take to change a switch.