fix(transmission): avoid lifetime in FromBytesError by owning data

Changed FromBytesError::InvalidBytes to take ownership of the byte slice by converting it to Vec<u8>. This removes the lifetime parameter from the enum, simplifying the API and preventing potential lifetime-related issues. The change ensures that error instances can be freely moved and stored without borrowing constraints.
This commit is contained in:
2026-01-18 19:19:06 +01:00
parent 9072ae01ad
commit ad9ca06bda

View File

@@ -45,7 +45,7 @@ impl Protocol300Transmission {
error!("Failed to parse Protocol300 transmission: invalid byte sequence (length: {}, first byte: 0x{:02X})", error!("Failed to parse Protocol300 transmission: invalid byte sequence (length: {}, first byte: 0x{:02X})",
bytes.len(), bytes.len(),
bytes.first().unwrap_or(&0x00)); bytes.first().unwrap_or(&0x00));
Err(FromBytesError::InvalidBytes(b)) Err(FromBytesError::InvalidBytes(b.to_owned()))
}, },
} }
} }
@@ -75,11 +75,11 @@ impl Protocol300Transmission {
/// Errors that can occur when getting a Protocol 300 Transmission from bytes /// Errors that can occur when getting a Protocol 300 Transmission from bytes
#[derive(Error, Debug, PartialEq, Eq)] #[derive(Error, Debug, PartialEq, Eq)]
pub enum FromBytesError<'a>{ pub enum FromBytesError{
#[error("Failed to parse message")] #[error("Failed to parse message")]
MessageParsing(#[from] message::MessageDecodingError), MessageParsing(#[from] message::MessageDecodingError),
#[error("Invalid bytes in vec")] #[error("Invalid bytes in vec")]
InvalidBytes(&'a [u8]) InvalidBytes(Vec<u8>)
} }