[−][src]Trait byteio::WriteBytesExt
Extends WriteBytes
with functions for writing numbers.
Examples
Write u16
s 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 u16
s 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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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
.