EthMRequest

Struct EthMRequest 

Source
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.

Source

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.

Source

pub fn from_iter( adapter_handle: HANDLE, iter: impl Iterator<Item = &'a IntermediateBuffer>, ) -> Self

Creates a new EthMRequest from an iterator over &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 references to IntermediateBuffer.
§Returns

A new EthMRequest.

Source

pub fn drain_success( &mut self, ) -> impl Iterator<Item = &'a IntermediateBuffer> + '_

Returns an iterator that yields Some(IntermediateBuffer) for each non-empty buffer in packets, in order, up to packet_success.

This method is used to drain the successful packets from the request. It iterates over the packets in the request, and for each packet that has a buffer (i.e., is not empty), it decreases the packet number and removes the buffer from the packet. The removed buffer (which is a mutable reference to an IntermediateBuffer) is then yielded by the iterator. This process continues until either all packets have been inspected or a number of packets equal to packet_success have been drained.

§Returns

An iterator over Option<&'a IntermediateBuffer>. Each Some(IntermediateBuffer) item in the iterator represents a successfully processed packet.

Source

pub fn drain(&mut self) -> impl Iterator<Item = &'a IntermediateBuffer> + '_

Returns an iterator that yields Some(IntermediateBuffer) for each non-empty buffer in packets.

This method is used to drain the packets from the request. It iterates over the packets in the request, and for each packet that has a buffer (i.e., is not empty), it decreases the packet number and removes the buffer from the packet. The removed buffer (which is a mutable reference to an IntermediateBuffer) is then yielded by the iterator.

§Returns

An iterator over Option<&'a IntermediateBuffer>. Each Some(IntermediateBuffer) item in the iterator represents a packet.

Source

pub fn get_packet_number(&self) -> u32

Returns the number of packets in the packets array.

This method is used to get the total number of packets currently stored in the packets array. The packets array is used to store the packets that are to be sent or received.

§Returns

A u32 value representing the total number of packets in the packets array.

Source

pub fn reset(&mut self)

Erases all EthPacketMut instances within the packets array and releases all references.

This method is used to reset the state of the EthMRequest instance. It iterates over the packets array, setting each buffer field to None, effectively releasing all references to IntermediateBuffer instances. It also resets the packet_number and packet_success counters to 0.

Source

pub fn get_packet_success(&self) -> u32

Returns the number of successfully processed packets.

This method is used to get the total number of packets that have been successfully processed. The packet_success field is incremented each time a packet is successfully processed.

§Returns

A u32 value representing the total number of successfully processed packets.

Source

pub fn push(&mut self, packet: &'a IntermediateBuffer) -> Result<()>

Adds an IntermediateBuffer to the packets array if there’s available space.

This method is used to add a new packet to the packets array. It first checks if the current number of packets is less than the maximum allowed (N). If there is space available, it finds the first empty slot in the packets array and inserts the new packet there, incrementing the packet_number counter. If the packets array is full, it returns an Err with ERROR_BUFFER_OVERFLOW.

§Arguments
  • packet: A mutable reference to an IntermediateBuffer representing the new packet to be added.
§Returns
  • Ok(()) if the packet was successfully added.
  • Err(ERROR_BUFFER_OVERFLOW.into()) if the packets array is full.
Source

pub fn append<I>(&mut self, packets: I) -> Result<()>
where I: Iterator<Item = &'a IntermediateBuffer>,

Consumes packets from an Iterator, moving them into self.

This method is used to add packets from an iterator to the packets array. It iterates over the packets provided by the iterator, and for each packet, it checks if there is space available in the packets array. If there is space available, it finds the first empty slot in the packets array and inserts the new packet there, incrementing the packet_number counter. If the packets array is full, it returns an Err with ERROR_BUFFER_OVERFLOW.

§Arguments
  • packets: An iterator that yields mutable references to IntermediateBuffer instances.
§Returns
  • Ok(()) if all packets from the iterator were successfully added.
  • Err(ERROR_BUFFER_OVERFLOW.into()) if the packets array is full.

Auto Trait Implementations§

§

impl<'a, const N: usize> Freeze for EthMRequest<'a, N>

§

impl<'a, const N: usize> RefUnwindSafe for EthMRequest<'a, N>

§

impl<'a, const N: usize> Send for EthMRequest<'a, N>

§

impl<'a, const N: usize> Sync for EthMRequest<'a, N>

§

impl<'a, const N: usize> Unpin for EthMRequest<'a, N>

§

impl<'a, const N: usize> UnwindSafe for EthMRequest<'a, N>

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.