fix: improve error handling and code robustness
- state_machine.rs: if-let replaces is_some()+take().unwrap() - state_machine.rs: expect() replaces unwrap() with invariant docs - wifi/mod.rs: send_result uses self.id() instead of hardcoded string
This commit is contained in:
@@ -51,8 +51,7 @@ impl StateMachine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 有待执行的触发器时,跳过 sequence 剩余 step,立即切换状态
|
// 有待执行的触发器时,跳过 sequence 剩余 step,立即切换状态
|
||||||
if self.pending_trigger_target.is_some() {
|
if let Some(target_state) = self.pending_trigger_target.take() {
|
||||||
let target_state = self.pending_trigger_target.take().unwrap();
|
|
||||||
self.transition_to_state(&target_state)?;
|
self.transition_to_state(&target_state)?;
|
||||||
return Ok(self.current_state != old_state);
|
return Ok(self.current_state != old_state);
|
||||||
}
|
}
|
||||||
@@ -273,7 +272,8 @@ impl StateMachine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(free_states.last().unwrap().0.clone())
|
// free_states 非空已由上方 bail! 保证
|
||||||
|
Ok(free_states.last().expect("free_states is non-empty").0.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn select_weighted_next_state(&self, entries: &[NextStateEntry]) -> Option<String> {
|
fn select_weighted_next_state(&self, entries: &[NextStateEntry]) -> Option<String> {
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ impl WifiPlugin {
|
|||||||
.context("wifi plugin context is not initialized")?;
|
.context("wifi plugin context is not initialized")?;
|
||||||
|
|
||||||
ctx.tx.send(Envelope {
|
ctx.tx.send(Envelope {
|
||||||
from: "wifi".to_string(),
|
from: self.id().to_string(),
|
||||||
to: Destination::Broadcast,
|
to: Destination::Broadcast,
|
||||||
message: Message::WifiResult(payload),
|
message: Message::WifiResult(payload),
|
||||||
})?;
|
})?;
|
||||||
|
|||||||
Reference in New Issue
Block a user