pub struct EthMRequest<'a, const N: usize> { /* private fields */ }
Expand description
This structure represents a request for multiple Ethernet packets, containing a network adapter handle, packet number, packet success count, and an array of EthPacket
instances.
A Rust equivalent for the _ETH_M_REQUEST structure.
adapter_handle
is a handle to the network adapter associated with this request. packet_number
is the number of packets in the packets
array. packet_success
is the number of packets that have been successfully processed. packets
is an array of EthPacket
instances representing the Ethernet packets for this request.
Implementations§
Source§impl<'a, const N: usize> EthMRequest<'a, N>
Provides methods for manipulating the EthPacket
instances within an EthMRequest
.
impl<'a, const N: usize> EthMRequest<'a, N>
Provides methods for manipulating the EthPacket
instances within an EthMRequest
.
Sourcepub fn new(adapter_handle: HANDLE) -> Self
pub fn new(adapter_handle: HANDLE) -> Self
Creates a new EthMRequest
with the specified adapter handle.
All packets in the request are initialized to empty.
Sourcepub fn from_iter(
adapter_handle: HANDLE,
iter: impl Iterator<Item = &'a mut IntermediateBuffer>,
) -> Self
pub fn from_iter( adapter_handle: HANDLE, iter: impl Iterator<Item = &'a mut IntermediateBuffer>, ) -> Self
Creates a new EthMRequest
from an iterator over &mut IntermediateBuffer
.
This constructor will attempt to consume up to N
items from the iterator to initialize the packets
array.
If the iterator contains fewer than N
items, the remaining entries in the packets
array will be left as None
.
§Arguments
adapter_handle
: A handle to the network adapter associated with this request.iter
: An iterator over mutable references toIntermediateBuffer
.
§Returns
A new EthMRequest
.
Sourcepub fn drain_success(
&mut self,
) -> impl Iterator<Item = &'a mut IntermediateBuffer> + '_
pub fn drain_success( &mut self, ) -> impl Iterator<Item = &'a mut IntermediateBuffer> + '_
Returns an iterator that yields Some(IntermediateBuffer)
for each non-empty buffer in packets
, in order,
up to packet_success
.
§Description
This function, drain_success
, operates on mutable reference to the current instance of the struct.
It returns an iterator that goes over each non-empty buffer in packets
, in their
original order, but only up to the index specified by packet_success
. This iterator will
yield Some(IntermediateBuffer)
for each of these buffers. These buffers represent packets
that have been successfully read from the driver.
Once called, this method drains the non-empty buffers from packets
, up to packet_success
making them empty (None
).
§Returns
This function returns an implementation of Iterator trait. The iterator item type is a mutable reference
to an IntermediateBuffer
(&'a mut IntermediateBuffer
). This iterator can be used to iterate over the drained buffers.
Sourcepub fn drain(&mut self) -> impl Iterator<Item = &'a mut IntermediateBuffer> + '_
pub fn drain(&mut self) -> impl Iterator<Item = &'a mut IntermediateBuffer> + '_
Returns an iterator that yields Some(IntermediateBuffer)
for each non-empty buffer in packets
.
§Description
This function, drain
, operates on mutable reference to the current instance of the struct.
It returns an iterator which yields mutable references to IntermediateBuffer
for each non-empty buffer in packets
,
and it yields them in the order they occur in packets
.
Once called, this method drains the non-empty buffers from packets
, making them empty (None
).
§Returns
This function returns an implementation of Iterator trait. The iterator item type is a mutable reference
to an IntermediateBuffer
(&'a mut IntermediateBuffer
). This iterator can be used to iterate over the drained buffers.
Sourcepub fn get_packet_number(&self) -> u32
pub fn get_packet_number(&self) -> u32
Returns the number of packets in the packets
array.
This provides a count of all packets, regardless of whether they’ve been successfully processed.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Erases all EthPacket
instances within the packets
array and releases all references.
After this method is called, all EthPacket
instances within the packets
array will be empty (i.e., their buffer
fields will be None
), and the packet number will be reset to 0.
Sourcepub fn get_packet_success(&self) -> u32
pub fn get_packet_success(&self) -> u32
Returns the number of successfully processed packets
Sourcepub fn push(&mut self, packet: &'a mut IntermediateBuffer) -> Result<()>
pub fn push(&mut self, packet: &'a mut IntermediateBuffer) -> Result<()>
Adds an IntermediateBuffer
to the packets
array if there’s available space.
This effectively wraps the buffer into an EthPacket
and stores it in the array.
The packet_number
field of the EthMRequest
is automatically incremented to reflect the addition of the new packet.
If there is no available space in the array (i.e., if the packet_number
is equal to the array length N
), this method returns an error, specifically ERROR_INVALID_PARAMETER
.
This method provides an idiomatic way of adding new packets to an EthMRequest
in Rust.
§Arguments
packet
- A mutable reference to theIntermediateBuffer
to be added to thepackets
array.
§Returns
Ok(())
if the buffer was successfully added as a packet.Err(ERROR_BUFFER_OVERFLOW.into())
if thepackets
array is full.