pub struct UdpWriter<'w, W5500> { /* private fields */ }
Expand description
Streaming writer for a UDP socket buffer.
This implements the Seek
traits.
Created with Udp::udp_writer
.
Example
use w5500_hl::{
io::Write,
ll::{Registers, Sn::Sn0},
net::{Ipv4Addr, SocketAddrV4},
Udp, UdpWriter,
};
const DEST: SocketAddrV4 = SocketAddrV4::new(Ipv4Addr::new(192, 0, 2, 1), 8081);
w5500.udp_bind(Sn0, 8080)?;
let mut udp_writer: UdpWriter<_> = w5500.udp_writer(Sn0)?;
let data_header: [u8; 10] = [0; 10];
let n_written: u16 = udp_writer.write(&data_header)?;
assert_eq!(usize::from(n_written), data_header.len());
let data: [u8; 123] = [0; 123];
let n_written: u16 = udp_writer.write(&data)?;
assert_eq!(usize::from(n_written), data.len());
udp_writer.udp_send_to(&DEST)?;
Implementations§
source§impl<'w, W5500: Registers> UdpWriter<'w, W5500>
impl<'w, W5500: Registers> UdpWriter<'w, W5500>
sourcepub fn udp_send_to(self, addr: &SocketAddrV4) -> Result<(), W5500::Error>
pub fn udp_send_to(self, addr: &SocketAddrV4) -> Result<(), W5500::Error>
Send all data previously written with UdpWriter::write
and
UdpWriter::write_all
to the given address.
Panics
- (debug) The socket must be opened as a UDP socket.
Trait Implementations§
source§impl<'w, W5500: PartialEq> PartialEq for UdpWriter<'w, W5500>
impl<'w, W5500: PartialEq> PartialEq for UdpWriter<'w, W5500>
source§impl<'w, W5500> Seek for UdpWriter<'w, W5500>
impl<'w, W5500> Seek for UdpWriter<'w, W5500>
source§fn seek<E>(&mut self, pos: SeekFrom) -> Result<(), Error<E>>
fn seek<E>(&mut self, pos: SeekFrom) -> Result<(), Error<E>>
Seek to an offset, in bytes, within the socket buffer. Read more
source§fn stream_len(&self) -> u16
fn stream_len(&self) -> u16
Return the length of the stream, in bytes. Read more
source§fn stream_position(&self) -> u16
fn stream_position(&self) -> u16
Returns the current seek position from the start of the stream.
source§impl<'w, W5500: Registers> Write<<W5500 as Registers>::Error> for UdpWriter<'w, W5500>
impl<'w, W5500: Registers> Write<<W5500 as Registers>::Error> for UdpWriter<'w, W5500>
source§fn write(&mut self, buf: &[u8]) -> Result<u16, W5500::Error>
fn write(&mut self, buf: &[u8]) -> Result<u16, W5500::Error>
Write data to the socket buffer, and return the number of bytes written.
impl<'w, W5500: Eq> Eq for UdpWriter<'w, W5500>
impl<'w, W5500> StructuralEq for UdpWriter<'w, W5500>
impl<'w, W5500> StructuralPartialEq for UdpWriter<'w, W5500>
Auto Trait Implementations§
impl<'w, W5500> RefUnwindSafe for UdpWriter<'w, W5500>where W5500: RefUnwindSafe,
impl<'w, W5500> Send for UdpWriter<'w, W5500>where W5500: Send,
impl<'w, W5500> Sync for UdpWriter<'w, W5500>where W5500: Sync,
impl<'w, W5500> Unpin for UdpWriter<'w, W5500>
impl<'w, W5500> !UnwindSafe for UdpWriter<'w, W5500>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more