pub unsafe trait Writer {
Show 42 methods fn remaining(&self) -> usize; fn chunk(&mut self) -> &mut [u8]Notable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]impl Reader for &[u8]impl Writer for &mut [u8]impl<T> Writable for &[T]where
    T: Writable + ByteSize,
; unsafe fn advance(&mut self, num_bytes: usize) -> Result<(), WriteError>; fn write<T>(&mut self, writable: T) -> Result<(), WriteError>
   where
        T: Writable + ByteSize,
        Self: Sized
, { ... } fn write_repeated<T>(
        &mut self,
        writable: T,
        count: usize
    ) -> Result<(), WriteError>
   where
        T: Writable + ByteSize,
        Self: Sized
, { ... } fn write_with_size<T>(
        &mut self,
        writable: T,
        num_bytes: usize
    ) -> Result<(), WriteError>
   where
        T: WritableWithSize,
        Self: Sized
, { ... } fn write_from_reader<T: Reader>(
        &mut self,
        reader: T
    ) -> Result<(), Box<dyn Error>>
   where
        Self: Sized
, { ... } fn has_remaining(&self) -> boolNotable traits for boolimpl Readable for boolimpl Writable for bool { ... } fn write_bytes(&mut self, bytes: &[u8]) -> Result<(), WriteError> { ... } fn write_bool(&mut self, val: bool) -> Result<(), WriteError> { ... } fn write_u8(&mut self, val: u8) -> Result<(), WriteError> { ... } fn write_i8(&mut self, val: i8) -> Result<(), WriteError> { ... } fn write_u16_ne(&mut self, val: u16) -> Result<(), WriteError> { ... } fn write_i16_ne(&mut self, val: i16) -> Result<(), WriteError> { ... } fn write_u32_ne(&mut self, val: u32) -> Result<(), WriteError> { ... } fn write_i32_ne(&mut self, val: i32) -> Result<(), WriteError> { ... } fn write_u64_ne(&mut self, val: u64) -> Result<(), WriteError> { ... } fn write_i64_ne(&mut self, val: i64) -> Result<(), WriteError> { ... } fn write_u128_ne(&mut self, val: u128) -> Result<(), WriteError> { ... } fn write_i128_ne(&mut self, val: i128) -> Result<(), WriteError> { ... } fn write_f32_ne(&mut self, val: f32) -> Result<(), WriteError> { ... } fn write_f64_ne(&mut self, val: f64) -> Result<(), WriteError> { ... } fn write_u16_be(&mut self, val: u16) -> Result<(), WriteError> { ... } fn write_i16_be(&mut self, val: i16) -> Result<(), WriteError> { ... } fn write_u32_be(&mut self, val: u32) -> Result<(), WriteError> { ... } fn write_i32_be(&mut self, val: i32) -> Result<(), WriteError> { ... } fn write_u64_be(&mut self, val: u64) -> Result<(), WriteError> { ... } fn write_i64_be(&mut self, val: i64) -> Result<(), WriteError> { ... } fn write_u128_be(&mut self, val: u128) -> Result<(), WriteError> { ... } fn write_i128_be(&mut self, val: i128) -> Result<(), WriteError> { ... } fn write_f32_be(&mut self, val: f32) -> Result<(), WriteError> { ... } fn write_f64_be(&mut self, val: f64) -> Result<(), WriteError> { ... } fn write_u16_le(&mut self, val: u16) -> Result<(), WriteError> { ... } fn write_i16_le(&mut self, val: i16) -> Result<(), WriteError> { ... } fn write_u32_le(&mut self, val: u32) -> Result<(), WriteError> { ... } fn write_i32_le(&mut self, val: i32) -> Result<(), WriteError> { ... } fn write_u64_le(&mut self, val: u64) -> Result<(), WriteError> { ... } fn write_i64_le(&mut self, val: i64) -> Result<(), WriteError> { ... } fn write_u128_le(&mut self, val: u128) -> Result<(), WriteError> { ... } fn write_i128_le(&mut self, val: i128) -> Result<(), WriteError> { ... } fn write_f32_le(&mut self, val: f32) -> Result<(), WriteError> { ... } fn write_f64_le(&mut self, val: f64) -> Result<(), WriteError> { ... }
}

Required Methods

Returns the number of bytes remaining from the current position until the current end of the Writer.

The number of bytes remaining() may increase if the Writer allocates more memory. This represents only the remaining number of bytes at this point in time.

Returns a mutable chunk of data starting at the current position and less than or equal to the number of remaining() bytes.

This method allows for a Writer to be stored non-contiguously; that is, the chunk() of data returned is not necessarily all of the bytes remaining() in the Writer.

This method may return a slice of zero bytes if and only if the number of bytes remaining() is 0.

Advances the internal cursor of this Writer by num_bytes.

Unsafe

This method is unsafe because there is no guarantee that the bytes being advanced over have been initialized.

Provided Methods

Writes a Writable type as bytes.

Errors

This method returns a WriteError::CapacityTooLow error if writable::byte_size() is greater than [remaining()].

Examples
use cornflakes::Writer;

let mut buffer1: Vec<u8> = vec![];
buffer.write(21u32)?;
buffer.write(b"hello, world!")?;
buffer.write([(); 22])?;

let mut buffer2: Vec<u8> = vec![];
21u32.write_to(&mut buffer2)?;
b"hello, world!".write_to(&mut buffer2)?;
[(); 22].write_to(&mut buffer2)?;

assert_eq!(buffer1, buffer2);

Writes the same Writable count many times.

Examples
use cornflakes::Writer;

let mut buffer1: Vec<u8> = vec![];

for _ in 0..10 {
    buffer1.write_u8(0)?;
}

let mut buffer2: Vec<u8> = vec![];
buffer2.write_repeated(0u8, 10)?;

let mut buffer3: Vec<u8> = vec![];
buffer3.write_bytes(&[0; 10])?;

assert_eq!(buffer1, buffer2, buffer3);

Writes a WritableWithSize type as bytes with the given number of bytes.

Examples
use cornflakes::Writer;

let mut buffer: Vec<u8> = vec![];

// Values {{{

let screen_x: u16 = 33;
let screen_y: u16 = 27;

buffer.write(1u32)?;

// Write the `u16` values as 4 bytes each, so that they can be included
// in a list of 'values' in X11.
buffer.write_with_size(screen_x, 4)?;
buffer.write_with_size(screen_y, 4)?;

// }}}

Writes the bytes of a Reader to self.

Errors

This method returns a WriteError::CapacityTooLow error if reader.remaining() is greater than self.remaining().

Returns whether there is more than zero bytes remaining in self.

Writes a slice of bytes to self.

Errors

This method returns a WriteError::CapacityTooLow error if slice.len() is greater than self.remaining().

Writes a boolean value as one byte.

Advances the internal cursor by 1 byte.

Errors

This method returns a WriteError::CapacityTooLow error if there are 0 bytes remaining().

Writes an 8-bit unsigned integer to self.

Advances the internal cursor by 1 byte.

Errors

This method returns a WriteError::CapacityTooLow error if there are 0 bytes remaining().

Writes an 8-bit signed integer to self.

Advances the internal cursor by 1 byte.

Errors

This method returns a WriteError::CapacityTooLow error if there are 0 bytes remaining().

Writes a 16-bit unsigned integer to self with the native endianness.

Advances the internal cursor by 2 bytes.

Errors

This method returns a WriteError::CapacityTooLow error if there are less than 2 bytes remaining().

Writes a 16-bit signed integer to self with the native endianness.

Advances the internal cursor by 2 bytes.

Errors

This method returns a WriteError::CapacityTooLow error if there are less than 2 bytes remaining().

Writes a 32-bit unsigned integer to self with the native endianness.

Advances the internal cursor by 4 bytes.

Errors

This method returns a WriteError::CapacityTooLow error if there are less than 4 bytes remaining().

Writes a 32-bit signed integer to self with the native endianness.

Advances the internal cursor by 4 bytes.

Errors

This method returns a WriteError::CapacityTooLow error if there are less than 4 bytes remaining().

Writes a 64-bit unsigned integer to self with the native endianness.

Advances the internal cursor by 8 bytes.

Errors

This method returns a WriteError::CapacityTooLow error if there are less than 8 bytes remaining().

Writes a 64-bit signed integer to self with the native endianness.

Advances the internal cursor by 8 bytes.

Errors

This method returns a WriteError::CapacityTooLow error if there are less than 8 bytes remaining().

Writes a 128-bit unsigned integer to self with the native endianness.

Advances the internal cursor by 16 bytes.

Errors

This method returns a WriteError::CapacityTooLow error if there are less than 16 bytes remaining().

Writes a 128-bit signed integer to self with the native endianness.

Advances the internal cursor by 16 bytes.

Errors

This method returns a WriteError::CapacityTooLow error if there are less than 16 bytes remaining().

Writes a 32-bit floating point number to self with the native endianness.

Advances the internal cursor by 4 bytes.

Errors

This method returns a WriteError::CapacityTooLow error if there are less than 4 bytes remaining().

Writes a 64-bit floating point number to self with the native endianness.

Advances the internal cursor by 8 bytes.

Errors

This method returns a WriteError::CapacityTooLow error if there are less than 8 bytes remaining().

Writes a 16-bit unsigned integer to self with big endianness.

Advances the internal cursor by 2 bytes.

Errors

This method returns a WriteError::CapacityTooLow error if there are less than 2 bytes remaining().

Writes a 16-bit signed integer to self with big endianness.

Advances the internal cursor by 2 bytes.

Errors

This method returns a WriteError::CapacityTooLow error if there are less than 2 bytes remaining().

Writes a 32-bit unsigned integer to self with big endianness.

Advances the internal cursor by 4 bytes.

Errors

This method returns a WriteError::CapacityTooLow error if there are less than 4 bytes remaining().

Writes a 32-bit signed integer to self with big endianness.

Advances the internal cursor by 4 bytes.

Errors

This method returns a WriteError::CapacityTooLow error if there are less than 4 bytes remaining().

Writes a 64-bit unsigned integer to self with big endianness.

Advances the internal cursor by 8 bytes.

Errors

This method returns a WriteError::CapacityTooLow error if there are less than 8 bytes remaining().

Writes a 64-bit signed integer to self with big endianness.

Advances the internal cursor by 8 bytes.

Errors

This method returns a WriteError::CapacityTooLow error if there are less than 8 bytes remaining().

Writes a 128-bit unsigned integer to self with big endianness.

Advances the internal cursor by 16 bytes.

Errors

This method returns a WriteError::CapacityTooLow error if there are less than 16 bytes remaining().

Writes a 128-bit signed integer to self with big endianness.

Advances the internal cursor by 16 bytes.

Errors

This method returns a WriteError::CapacityTooLow error if there are less than 16 bytes remaining().

Writes a 32-bit floating point number to self with big endianness.

Advances the internal cursor by 4 bytes.

Errors

This method returns a WriteError::CapacityTooLow error if there are less than 4 bytes remaining().

Writes a 64-bit floating point number to self with big endianness.

Advances the internal cursor by 8 bytes.

Errors

This method returns a WriteError::CapacityTooLow error if there are less than 8 bytes remaining().

Writes a 16-bit unsigned integer to self with little endianness.

Advances the internal cursor by 2 bytes.

Errors

This method returns a WriteError::CapacityTooLow error if there are less than 2 bytes remaining().

Writes a 16-bit signed integer to self with little endianness.

Advances the internal cursor by 2 bytes.

Errors

This method returns a WriteError::CapacityTooLow error if there are less than 2 bytes remaining().

Writes a 32-bit unsigned integer to self with little endianness.

Advances the internal cursor by 4 bytes.

Errors

This method returns a WriteError::CapacityTooLow error if there are less than 4 bytes remaining().

Writes a 32-bit signed integer to self with little endianness.

Advances the internal cursor by 4 bytes.

Errors

This method returns a WriteError::CapacityTooLow error if there are less than 4 bytes remaining().

Writes a 64-bit unsigned integer to self with little endianness.

Advances the internal cursor by 8 bytes.

Errors

This method returns a WriteError::CapacityTooLow error if there are less than 8 bytes remaining().

Writes a 64-bit signed integer to self with little endianness.

Advances the internal cursor by 8 bytes.

Errors

This method returns a WriteError::CapacityTooLow error if there are less than 8 bytes remaining().

Writes a 128-bit unsigned integer to self with little endianness.

Advances the internal cursor by 16 bytes.

Errors

This method returns a WriteError::CapacityTooLow error if there are less than 16 bytes remaining().

Writes a 128-bit signed integer to self with little endianness.

Advances the internal cursor by 16 bytes.

Errors

This method returns a WriteError::CapacityTooLow error if there are less than 16 bytes remaining().

Writes a 32-bit floating point number to self with little endianness.

Advances the internal cursor by 4 bytes.

Errors

This method returns a WriteError::CapacityTooLow error if there are less than 4 bytes remaining().

Writes a 64-bit floating point number to self with little endianness.

Advances the internal cursor by 8 bytes.

Errors

This method returns a WriteError::CapacityTooLow error if there are less than 8 bytes remaining().

Implementations on Foreign Types

Implementors