fn udp_recv_from(
        &mut self,
        sn: Sn,
        buf: &mut [u8],
    ) -> Result<(u16, SocketAddrV4), Error<Self::Error>> {
        let rsr: u16 = match self.sn_rx_rsr(sn)?.checked_sub(UdpHeader::LEN) {
            Some(rsr) => rsr,
            // nothing to recieve
            None => return Err(Error::WouldBlock),
        };

        debug_assert_eq!(self.sn_sr(sn)?, Ok(SocketStatus::Udp));

        let mut ptr: u16 = self.sn_rx_rd(sn)?;
        let mut header: [u8; UdpHeader::LEN_USIZE] = [0; UdpHeader::LEN_USIZE];
        self.sn_rx_buf(sn, ptr, &mut header)?;
        ptr = ptr.wrapping_add(UdpHeader::LEN);
        let header: UdpHeader = UdpHeader::deser(header);

        // not all data as indicated by the header has been buffered
        if rsr < header.len {
            return Err(Error::WouldBlock);
        }

        let read_size: u16 = min(header.len, buf.len().try_into().unwrap_or(u16::MAX));
        if read_size != 0 {
            self.sn_rx_buf(sn, ptr, &mut buf[..read_size.into()])?;
        }
        ptr = ptr.wrapping_add(header.len);
        self.set_sn_rx_rd(sn, ptr)?;
        self.set_sn_cr(sn, SocketCommand::Recv)?;
        Ok((read_size, header.origin))
    }
/// Receives a single datagram message on the socket.
/// On success, returns the number of bytes read and the origin.
///
/// The function must be called with valid byte array `buf` of sufficient
/// size to hold the message bytes.
/// If a message is too long to fit in the supplied buffer, excess bytes
/// will be discarded.
///
/// # Comparison to [`std::net::UdpSocket::recv_from`]
///
/// * This method will always discard excess bytes from the socket buffer.
/// * This method is non-blocking, use [`block`] to treat it as blocking.
///
/// # Errors
///
/// This method can only return:
///
/// * [`Error::Other`]
/// * [`Error::WouldBlock`]
///
/// # Panics
///
/// * (debug) The socket must be opened as a UDP socket.
///
/// # Example
///
/// ```no_run
/// # use embedded_hal_mock as h;
/// # let mut w5500 = w5500_ll::blocking::vdm::W5500::new(h::spi::Mock::new(&[]), h::pin::Mock::new(&[]));
/// use w5500_hl::{
///     ll::{Registers, Sn::Sn0},
///     block,
///     Udp,
/// };
///
/// w5500.udp_bind(Sn0, 8080)?;
/// let mut buf = [0; 10];
/// let (number_of_bytes, src_addr) = block!(w5500.udp_recv_from(Sn0, &mut buf))?;
///
/// // panics if bytes were discarded
/// assert!(
///     usize::from(number_of_bytes) < buf.len(),
///     "Buffer was too small to receive all data"
/// );
///
/// let filled_buf = &mut buf[..number_of_bytes.into()];
/// # Ok::<(), w5500_hl::Error<_>>(())
/// ```
///
/// [`std::net::UdpSocket::recv_from`]: https://doc.rust-lang.org/std/net/struct.UdpSocket.html#method.recv_from
/// [`block`]: crate::block
Receives a single datagram message on the socket.
On success, returns the number of bytes read and the origin.

The function must be called with valid byte array `buf` of sufficient
size to hold the message bytes.
If a message is too long to fit in the supplied buffer, excess bytes
will be discarded.
Receives a single datagram message on the socket . On success returns the number of bytes read and the origin . The function must be called with valid byte array ` buf ` of sufficient size to hold the message bytes . If a message is too long to fit in the supplied buffer excess bytes will be discarded .
fn udp_recv_from(
        &mut self,
        sn: Sn,
        buf: &mut [u8],
    ) -> Result<(u16, SocketAddrV4), Error<Self::Error>> {
        let rsr: u16 = match self.sn_rx_rsr(sn)?.checked_sub(UdpHeader::LEN) {
            Some(rsr) => rsr,
            // nothing to recieve
            None => return Err(Error::WouldBlock),
        };
        debug_assert_eq!(self.sn_sr(sn)?, Ok(SocketStatus::Udp));
        let mut ptr: u16 = self.sn_rx_rd(sn)?;
        let mut header: [u8; UdpHeader::LEN_USIZE] = [0; UdpHeader::LEN_USIZE];
        self.sn_rx_buf(sn, ptr, &mut header)?;
        ptr = ptr.wrapping_add(UdpHeader::LEN);
        let header: UdpHeader = UdpHeader::deser(header);
        // not all data as indicated by the header has been buffered
        if rsr < header.len {
            return Err(Error::WouldBlock);
        }
        let read_size: u16 = min(header.len, buf.len().try_into().unwrap_or(u16::MAX));
        if read_size != 0 {
            self.sn_rx_buf(sn, ptr, &mut buf[..read_size.into()])?;
        }
        ptr = ptr.wrapping_add(header.len);
        self.set_sn_rx_rd(sn, ptr)?;
        self.set_sn_cr(sn, SocketCommand::Recv)?;
        Ok((read_size, header.origin))
    }
fn udp_recv_from ( & mut self , sn : Sn , buf : & mut [ u8 ] , ) -> Result < ( u16 , SocketAddrV4 ) , Error < Self :: Error > > { let rsr : u16 = match self . sn_rx_rsr ( sn ) ? . checked_sub ( UdpHeader :: LEN ) { Some ( rsr ) => rsr , // nothing to recieve None => return Err ( Error :: WouldBlock ) , } ; debug_assert_eq ! ( self sn_sr ( sn ) Ok ( SocketStatus Udp ) ) ; let mut ptr : u16 = self . sn_rx_rd ( sn ) ? ; let mut header : [ u8 ; UdpHeader :: LEN_USIZE ] = [ 0 ; UdpHeader :: LEN_USIZE ] ; self . sn_rx_buf ( sn , ptr , & mut header ) ? ; ptr = ptr . wrapping_add ( UdpHeader :: LEN ) ; let header : UdpHeader = UdpHeader :: deser ( header ) ; // not all data as indicated by the header has been buffered if rsr < header . len { return Err ( Error :: WouldBlock ) ; } let read_size : u16 = min ( header . len , buf . len ( ) . try_into ( ) . unwrap_or ( u16 :: MAX ) ) ; if read_size != 0 { self . sn_rx_buf ( sn , ptr , & mut buf [ .. read_size . into ( ) ] ) ? ; } ptr = ptr . wrapping_add ( header . len ) ; self . set_sn_rx_rd ( sn , ptr ) ? ; self . set_sn_cr ( sn , SocketCommand :: Recv ) ? ; Ok ( ( read_size , header . origin ) ) }
Receives a single datagram message on the socket.
Receives a single datagram message on the socket .
&mut self
sn
Sn
buf
&mut [u8]
&mut self
sn
Sn
buf
&mut [u8]
comparison to [`std::net::udpsocket::recv_from`]
This method will always discard excess bytes from the socket buffer.
This method is non-blocking, use [`block`] to treat it as blocking.
This method will always discard excess bytes from the socket buffer . This method is non - blocking use [ ` block ` ] to treat it as blocking .
errors
This method can only return.

[`Error::Other`]
[`Error::WouldBlock`]
This method can only return . [ ` Error :: Other ` ] [ ` Error :: WouldBlock ` ]
panics
(debug) The socket must be opened as a UDP socket.
( debug ) The socket must be opened as a UDP socket .
example
None
use embedded_hal_mock as h;
None
let mut w5500 = w5500_ll::blocking::vdm::w5500::new(h::spi::mock::new(&[]), h::pin::mock::new(&[]));




panics if bytes were discarded
assert!(
usize::from(number_of_bytes) < buf.len(),
"Buffer was too small to receive all data"
).

let filled_buf = &mut buf[..number_of_bytes.into()].
panics if bytes were discarded assert! ( usize :: from ( number_of_bytes ) < buf . len () " Buffer was too small to receive all data " ) . let filled_buf = &mut buf [ .. number_of_bytes . into () ] .
ok::<(), w5500_hl::error<_>>(())
None