Error Handling

This commit is contained in:
2026-02-26 20:35:04 +01:00
parent ae15494e85
commit bb3892a239
8 changed files with 60 additions and 45 deletions

View File

@@ -18,6 +18,7 @@ pub use state::*;
#[derive(Debug, Clone)]
pub enum Message {
None,
DeviceInfo(Box<DeviceInfo>),
State(State),
Ping(Ping),
@@ -27,11 +28,13 @@ pub enum Message {
}
// helper to read fixed-size chunks
pub(super) fn take<const N: usize>(bytes: &mut &[u8]) -> Result<[u8; N], &'static str> {
pub(super) fn take<const N: usize>(
bytes: &mut &[u8],
) -> Result<[u8; N], Box<dyn std::error::Error>> {
if bytes.len() < N {
return Err("buffer too small");
return Err("buffer too small".into());
}
let (head, tail) = bytes.split_at(N);
*bytes = tail;
Ok(head.try_into().unwrap())
Ok(head.try_into()?)
}