[][src]Trait byteio::WriteBytesExt

pub trait WriteBytesExt: WriteBytes {
    fn write_u8(&mut self, n: u8) { ... }
fn try_write_u8(&mut self, n: u8) -> Result<()> { ... }
fn write_i8(&mut self, n: i8) { ... }
fn try_write_i8(&mut self, n: i8) -> Result<()> { ... }
fn write_u16<E: ByteOrder>(&mut self, n: u16) { ... }
fn try_write_u16<E: ByteOrder>(&mut self, n: u16) -> Result<()> { ... }
fn write_i16<E: ByteOrder>(&mut self, n: i16) { ... }
fn try_write_i16<E: ByteOrder>(&mut self, n: i16) -> Result<()> { ... }
fn write_u32<E: ByteOrder>(&mut self, n: u32) { ... }
fn try_write_u32<E: ByteOrder>(&mut self, n: u32) -> Result<()> { ... }
fn write_i32<E: ByteOrder>(&mut self, n: i32) { ... }
fn try_write_i32<E: ByteOrder>(&mut self, n: i32) -> Result<()> { ... }
fn write_u64<E: ByteOrder>(&mut self, n: u64) { ... }
fn try_write_u64<E: ByteOrder>(&mut self, n: u64) -> Result<()> { ... }
fn write_i64<E: ByteOrder>(&mut self, n: i64) { ... }
fn try_write_i64<E: ByteOrder>(&mut self, n: i64) -> Result<()> { ... }
fn write_u128<E: ByteOrder>(&mut self, n: u128) { ... }
fn try_write_u128<E: ByteOrder>(&mut self, n: u128) -> Result<()> { ... }
fn write_i128<E: ByteOrder>(&mut self, n: i128) { ... }
fn try_write_i128<E: ByteOrder>(&mut self, n: i128) -> Result<()> { ... }
fn write_f32<E: ByteOrder>(&mut self, n: f32) { ... }
fn try_write_f32<E: ByteOrder>(&mut self, n: f32) -> Result<()> { ... }
fn write_f64<E: ByteOrder>(&mut self, n: f64) { ... }
fn try_write_f64<E: ByteOrder>(&mut self, n: f64) -> Result<()> { ... } }

Extends WriteBytes with functions for writing numbers.

Examples

Write u16s into a buffer using native endianness:

use byteio::WriteBytesExt;
use byteorder::NativeEndian;

fn main() {
    let mut buf = [0; 4];

    {
        let mut buf = &mut buf[..];

        buf.write_u16::<NativeEndian>(256);
        buf.write_u16::<NativeEndian>(1);

        assert!(buf.is_empty());
    }
}

Try to write u16s into a buffer using a specific endianness:

use byteio::WriteBytesExt;
use byteorder::{BigEndian, LittleEndian};

fn main() -> byteio::Result<()> {
    let mut buf = [0; 4];

    {
        let mut buf = &mut buf[..];

        buf.try_write_u16::<BigEndian>(1)?;
        buf.try_write_u16::<LittleEndian>(1)?;

        assert!(buf.is_empty());
    }

    assert_eq!(buf, [0, 1, 1, 0]);

    Ok(())
}

Provided methods

fn write_u8(&mut self, n: u8)

Writes a u8 into the underlying buffer.

Panics

Panics if there are not enough bytes in self.

fn try_write_u8(&mut self, n: u8) -> Result<()>

Attempts to write a u8 into the underlying buffer.

If there are not enough bytes in self this function will return Error::EndOfStream.

fn write_i8(&mut self, n: i8)

Writes an i8 into the underlying buffer.

Panics

Panics if there are not enough bytes in self.

fn try_write_i8(&mut self, n: i8) -> Result<()>

Attempts to write an i8 into the underlying buffer.

If there are not enough bytes in self this function will return Error::EndOfStream.

fn write_u16<E: ByteOrder>(&mut self, n: u16)

Writes a u16 into the underlying buffer.

Panics

Panics if there are not enough bytes in self.

fn try_write_u16<E: ByteOrder>(&mut self, n: u16) -> Result<()>

Attempts to write a u16 into the underlying buffer.

If there are not enough bytes in self this function will return Error::EndOfStream.

fn write_i16<E: ByteOrder>(&mut self, n: i16)

Writes an i16 into the underlying buffer.

Panics

Panics if there are not enough bytes in self.

fn try_write_i16<E: ByteOrder>(&mut self, n: i16) -> Result<()>

Attempts to write an i16 into the underlying buffer.

If there are not enough bytes in self this function will return Error::EndOfStream.

fn write_u32<E: ByteOrder>(&mut self, n: u32)

Writes a u32 into the underlying buffer.

Panics

Panics if there are not enough bytes in self.

fn try_write_u32<E: ByteOrder>(&mut self, n: u32) -> Result<()>

Attempts to write a u32 into the underlying buffer.

If there are not enough bytes in self this function will return Error::EndOfStream.

fn write_i32<E: ByteOrder>(&mut self, n: i32)

Writes an i32 into the underlying buffer.

Panics

Panics if there are not enough bytes in self.

fn try_write_i32<E: ByteOrder>(&mut self, n: i32) -> Result<()>

Attempts to write an i32 into the underlying buffer.

If there are not enough bytes in self this function will return Error::EndOfStream.

fn write_u64<E: ByteOrder>(&mut self, n: u64)

Writes a u64 into the underlying buffer.

Panics

Panics if there are not enough bytes in self.

fn try_write_u64<E: ByteOrder>(&mut self, n: u64) -> Result<()>

Attempts to write a u64 into the underlying buffer.

If there are not enough bytes in self this function will return Error::EndOfStream.

fn write_i64<E: ByteOrder>(&mut self, n: i64)

Writes an i64 into the underlying buffer.

Panics

Panics if there are not enough bytes in self.

fn try_write_i64<E: ByteOrder>(&mut self, n: i64) -> Result<()>

Attempts to write an i64 into the underlying buffer.

If there are not enough bytes in self this function will return Error::EndOfStream.

fn write_u128<E: ByteOrder>(&mut self, n: u128)

Writes a u128 into the underlying buffer.

Panics

Panics if there are not enough bytes in self.

fn try_write_u128<E: ByteOrder>(&mut self, n: u128) -> Result<()>

Attempts to write a u128 into the underlying buffer.

If there are not enough bytes in self this function will return Error::EndOfStream.

fn write_i128<E: ByteOrder>(&mut self, n: i128)

Writes an i128 into the underlying buffer.

Panics

Panics if there are not enough bytes in self.

fn try_write_i128<E: ByteOrder>(&mut self, n: i128) -> Result<()>

Attempts to write an i128 into the underlying buffer.

If there are not enough bytes in self this function will return Error::EndOfStream.

fn write_f32<E: ByteOrder>(&mut self, n: f32)

Writes an IEEE754 f32 into the underlying buffer.

Panics

Panics if there are not enough bytes in self.

fn try_write_f32<E: ByteOrder>(&mut self, n: f32) -> Result<()>

Attempts to write an IEEE754 f32 into the underlying buffer.

If there are not enough bytes in self this function will return Error::EndOfStream.

fn write_f64<E: ByteOrder>(&mut self, n: f64)

Writes an IEEE754 f64 into the underlying buffer.

Panics

Panics if there are not enough bytes in self.

fn try_write_f64<E: ByteOrder>(&mut self, n: f64) -> Result<()>

Attempts to write an IEEE754 f64 into the underlying buffer.

If there are not enough bytes in self this function will return Error::EndOfStream.

Loading content...

Implementors

impl<W: WriteBytes> WriteBytesExt for W[src]

fn write_u8(&mut self, n: u8)[src]

fn try_write_u8(&mut self, n: u8) -> Result<()>[src]

fn write_i8(&mut self, n: i8)[src]

fn try_write_i8(&mut self, n: i8) -> Result<()>[src]

fn write_u16<E: ByteOrder>(&mut self, n: u16)[src]

fn try_write_u16<E: ByteOrder>(&mut self, n: u16) -> Result<()>[src]

fn write_i16<E: ByteOrder>(&mut self, n: i16)[src]

fn try_write_i16<E: ByteOrder>(&mut self, n: i16) -> Result<()>[src]

fn write_u32<E: ByteOrder>(&mut self, n: u32)[src]

fn try_write_u32<E: ByteOrder>(&mut self, n: u32) -> Result<()>[src]

fn write_i32<E: ByteOrder>(&mut self, n: i32)[src]

fn try_write_i32<E: ByteOrder>(&mut self, n: i32) -> Result<()>[src]

fn write_u64<E: ByteOrder>(&mut self, n: u64)[src]

fn try_write_u64<E: ByteOrder>(&mut self, n: u64) -> Result<()>[src]

fn write_i64<E: ByteOrder>(&mut self, n: i64)[src]

fn try_write_i64<E: ByteOrder>(&mut self, n: i64) -> Result<()>[src]

fn write_u128<E: ByteOrder>(&mut self, n: u128)[src]

fn try_write_u128<E: ByteOrder>(&mut self, n: u128) -> Result<()>[src]

fn write_i128<E: ByteOrder>(&mut self, n: i128)[src]

fn try_write_i128<E: ByteOrder>(&mut self, n: i128) -> Result<()>[src]

fn write_f32<E: ByteOrder>(&mut self, n: f32)[src]

fn try_write_f32<E: ByteOrder>(&mut self, n: f32) -> Result<()>[src]

fn write_f64<E: ByteOrder>(&mut self, n: f64)[src]

fn try_write_f64<E: ByteOrder>(&mut self, n: f64) -> Result<()>[src]

Loading content...