pub trait Protocol {
// Required methods
fn get_timeout(&self) -> Duration;
fn get_polling_interval(&self) -> Duration;
fn get_identifier(&self) -> &str;
fn read(&mut self, bytes: usize) -> Result<Vec<u8>, CommunicationError>;
fn write_packet_raw(
&mut self,
data: &[u8],
) -> Result<(), CommunicationError>;
fn read_packet_raw(
&mut self,
packet_code: u8,
) -> Result<Vec<u8>, CommunicationError>;
// Provided methods
fn write_packet_concrete<T>(
&mut self,
packet: T,
) -> Result<(), CommunicationError>
where T: PacketConstruct + Packet { ... }
fn read_packet_concrete<T>(&mut self) -> Result<T, CommunicationError>
where T: PacketParse + Packet { ... }
}Expand description
Core protocol trait for McuBoot communication
This trait defines the methods that all McuBoot protocol implementations must provide.
Required Methods§
Sourcefn get_timeout(&self) -> Duration
fn get_timeout(&self) -> Duration
Get the configured timeout duration for operations
Sourcefn get_polling_interval(&self) -> Duration
fn get_polling_interval(&self) -> Duration
Get the polling interval for checking responses
Sourcefn get_identifier(&self) -> &str
fn get_identifier(&self) -> &str
Get a string identifier for this protocol instance
Sourcefn write_packet_raw(&mut self, data: &[u8]) -> Result<(), CommunicationError>
fn write_packet_raw(&mut self, data: &[u8]) -> Result<(), CommunicationError>
Sourcefn read_packet_raw(
&mut self,
packet_code: u8,
) -> Result<Vec<u8>, CommunicationError>
fn read_packet_raw( &mut self, packet_code: u8, ) -> Result<Vec<u8>, CommunicationError>
Provided Methods§
Sourcefn write_packet_concrete<T>(
&mut self,
packet: T,
) -> Result<(), CommunicationError>where
T: PacketConstruct + Packet,
fn write_packet_concrete<T>(
&mut self,
packet: T,
) -> Result<(), CommunicationError>where
T: PacketConstruct + Packet,
Write a strongly-typed packet to the device
This method handles packet construction and transmission for any type that implements the required packet traits.
§Arguments
packet- The packet to send
§Returns
A Result indicating success or error
§Errors
Any errors that occured while writing, from being unable to write to invalid CRC checksum.
Sourcefn read_packet_concrete<T>(&mut self) -> Result<T, CommunicationError>where
T: PacketParse + Packet,
fn read_packet_concrete<T>(&mut self) -> Result<T, CommunicationError>where
T: PacketParse + Packet,
Read a strongly-typed packet from the device
This method handles packet reception and parsing for any type that implements the required packet traits.
§Returns
A Result containing the parsed packet or an error
§Errors
Any errors that occured while reading, from being unable to read to invalid CRC checksum.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.