[][src]Struct iostream::io::memory::memory_stream::MemoryStream

pub struct MemoryStream { /* fields omitted */ }

the memory stream from memory,you can use it,wr memory

Methods

impl MemoryStream[src]

impl MemoryStream[src]

pub fn to_vec(&self) -> Vec<u8>[src]

return current stream data to Vec

pub fn clear(&mut self)[src]

Clears the vector, removing all values,and set position =0

Trait Implementations

impl Stream for MemoryStream[src]

fn read_all(&mut self, buf: &mut Vec<u8>) -> Result<usize, StreamError>[src]

Examples

    use iostream::io::*;

    let mut ms=MemoryStream::new();
    let data:[u8;1024]=[55;1024];
    ms.write_all(&data).unwrap();

    ms.set_position(0).unwrap();

    let mut p:Vec<u8>=Vec::new();
    ms.read_all(&mut p).unwrap();

    for i  in p {
    print!("{}",i);
    }

    println!();

    ms.set_position(0).unwrap();
    let mut p:Vec<u8>=vec![0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff];
    ms.read_all(&mut p).unwrap();

    for i  in p {
    print!("{}",i);
    }
    println!();

fn read(
    &mut self,
    buf: &mut [u8],
    offset: usize,
    count: usize
) -> Result<usize, StreamError>
[src]

Examples

    use iostream::io::*;
    let mut ms=MemoryStream::new();
    let data:[u8;1024]=[55;1024];
    ms.write_all(&data).unwrap();

    ms.set_position(0).unwrap();

    let mut data:Vec<u8>=vec![0;250];
    let len=data.len();
    let size = ms.read(&mut data, 0,len).unwrap();

fn read_byte(&mut self) -> Result<u8, StreamError>[src]

Examples

   use iostream::io::*;

   let data:[u8;10]=[5;10];
   let mut ms= MemoryStream::new_to(&data);

   for s in 0..10 {
   let d=  ms.read_byte().unwrap();
   print!("{}",d);
   }

fn write_all(&mut self, buf: &[u8]) -> Result<(), Box<dyn Error>>[src]

Examples

use iostream::io::*;

let mut ms= MemoryStream::new();
let data: [u8; 1024] = [2; 1024];
ms.write_all(&data).unwrap();

fn write(
    &mut self,
    buf: &[u8],
    offset: usize,
    count: usize
) -> Result<usize, Box<dyn Error>>
[src]

Examples

use iostream::io::*;
let mut ms= MemoryStream::new();
let data2:[u8;100]=[2;100];
ms.write(&data2,50,50).unwrap();

fn copy_to(&mut self, target: &mut dyn Stream) -> Result<(), Box<dyn Error>>[src]

copy current stream to target stream # Examples ```rust use iostream::io::*; use std::fs::File; Read more

Auto Trait Implementations

Blanket Implementations

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

impl<T> From<T> for T[src]

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

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> 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> Borrow<T> for T where
    T: ?Sized
[src]

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

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