Skip to main content

WritePacket

Trait WritePacket 

Source
pub trait WritePacket: Write {
    // Provided methods
    fn write_packet_unchecked<P: Packet>(&mut self, packet: &P) -> Result<usize> { ... }
    fn write_packet<P: Packet>(&mut self, packet: &P) -> Result<usize> { ... }
    fn write_packet_with_checksum<P: Packet>(
        &mut self,
        packet: &P,
    ) -> Result<usize> { ... }
}
Expand description

A helper trait which implemented for std::io::Write. Contains methods for writing Packets to the Writer.

It is better to use std::io::BufWriter to avoid unnecessary syscalls, since we have to read one byte at a time to check for escaped by MARK_BYTE bytes.

Provided Methods§

Source

fn write_packet_unchecked<P: Packet>(&mut self, packet: &P) -> Result<usize>

Writes a packet to the Writer.

The function doesn’t calculate checksum and instead writes whatever is present in the packet itself. So you have to use Packet::calculate_checksum before writing. Use Self::write_packet to calculate checksum while writing bytes.

§Errors

Will return Err if Packet::len_of_packet less than Packet::DATA_BEGIN_INDEX + 1 which is nonsense.

Source

fn write_packet<P: Packet>(&mut self, packet: &P) -> Result<usize>

Similar to WritePacket::write_packet_unchecked, but it will calculate checksum while writing bytes to the writer.

§Errors

Will return Err if Packet::len_of_packet less than Packet::DATA_BEGIN_INDEX + 1 which is nonsense.

Source

fn write_packet_with_checksum<P: Packet>(&mut self, packet: &P) -> Result<usize>

👎Deprecated since 1.1.0

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<W: Write + ?Sized> WritePacket for W