[][src]Struct rubble::bytes::ByteWriter

pub struct ByteWriter<'a>(_);

Wrapper around a byte slice that can be used to encode data into bytes.

All write_* methods on this type will return Error::Eof when the underlying buffer slice is full.

Methods

impl<'a> ByteWriter<'a>[src]

pub fn new(buf: &'a mut [u8]) -> Self[src]

Creates a writer that will write to buf.

pub fn into_rest(self) -> &'a mut [u8][src]

Consumes self and returns the part of the contained buffer that has not yet been written to.

pub fn rest(&mut self) -> &mut [u8][src]

Returns the raw buffer this ByteWriter would write to.

Combined with skip, this method allows advanced operations on the underlying byte buffer.

pub fn skip(&mut self, bytes: usize) -> Result<(), Error>[src]

Skips the given number of bytes in the output data without writing anything there.

This is a potentially dangerous operation that should only be used when necessary (eg. when the skipped data will be filled in by other code). If the skipped bytes are not written, they will probably contain garbage data from an earlier use of the underlying buffer.

#[must_use]
pub fn split_off(&mut self, len: usize) -> Result<Self, Error>
[src]

Creates and returns another ByteWriter that can write to the next len Bytes in the buffer.

self will be modified to point after the split-off bytes.

Note that if the created ByteWriter is not used, the bytes will contain whatever contents they had before creating self (ie. most likely garbage data left over from earlier use). If you are really sure you want that, skip is a more explicit way of accomplishing that.

pub fn split_next_mut(&mut self) -> Option<&'a mut u8>[src]

Splits off the next byte in the buffer.

The writer will be advanced to point to the rest of the underlying buffer.

This allows filling in the value of the byte later, after writing more data.

For a similar, but more flexible operation, see split_off.

pub fn space_left(&self) -> usize[src]

Returns the number of bytes that can be written to self until it is full.

pub fn write_slice(&mut self, other: &[u8]) -> Result<(), Error>[src]

Writes all bytes from other to self.

Returns Error::Eof when self does not have enough space left to fit other. In that case, self will not be modified.

pub fn write_u8(&mut self, byte: u8) -> Result<(), Error>[src]

Writes a single byte to self.

Returns Error::Eof when no space is left.

pub fn write_u16_le(&mut self, value: u16) -> Result<(), Error>[src]

Writes a u16 to self, using Little Endian byte order.

If self does not have enough space left, an error will be returned and no bytes will be written to self.

pub fn write_u32_le(&mut self, value: u32) -> Result<(), Error>[src]

Writes a u32 to self, using Little Endian byte order.

If self does not have enough space left, an error will be returned and no bytes will be written to self.

pub fn write_u64_le(&mut self, value: u64) -> Result<(), Error>[src]

Writes a u64 to self, using Little Endian byte order.

If self does not have enough space left, an error will be returned and no bytes will be written to self.

Auto Trait Implementations

impl<'a> Send for ByteWriter<'a>

impl<'a> Sync for ByteWriter<'a>

Blanket Implementations

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> From for T[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]