[][src]Trait floaout::io::read::ReadBytesFor

pub trait ReadBytesFor<T>: Read {
    fn read_be_bytes_for(&mut self, size: usize) -> Result<T>;
fn read_le_bytes_for(&mut self, size: usize) -> Result<T>; }

This trait reads bytes for size. This is because, size is unknown in String.

Required methods

fn read_be_bytes_for(&mut self, size: usize) -> Result<T>

This method reads bytes in big-endian byte order.

Examples

use std::io;
use std::fs::File;
use floaout::io::read::ReadBytesFor;
 
fn main() -> io::Result<()> {
    let mut f = File::open("foo.txt")?;
 
    // read String for size of 3 in big-endian byte order
    let string: String = f.read_be_bytes_for(3)?;
 
    Ok(())
}

fn read_le_bytes_for(&mut self, size: usize) -> Result<T>

This method reads bytes in little-endian byte order.

Examples

use std::io;
use std::fs::File;
use floaout::io::read::ReadBytesFor;
 
fn main() -> io::Result<()> {
    let mut f = File::open("foo.txt")?;
 
    // read Vec<u8> for size of 1 in little-endian byte order
    let vec_u8: Vec<u8> = f.read_le_bytes_for(1)?;
 
    Ok(())
}
Loading content...

Implementors

impl<R: Read + ?Sized> ReadBytesFor<Sample> for R[src]

impl<R: Read + ?Sized> ReadBytesFor<String> for R[src]

impl<R: Read + ?Sized> ReadBytesFor<Vec<u8>> for R[src]

Loading content...