Error Handling
This commit is contained in:
@@ -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()?)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user