Struct bi::Bi[][src]

pub struct Bi { /* fields omitted */ }

Bi

This struct helps with controlling multiple tasks reading data into memory.

For examples, your program parses files. Naturally it scans for files on the system, then reads them into memory, and does the job. Now, if you want to limit total memory it uses at a time to 256 MiB, you can do this:

use {
    core::time::Duration,
    std::{
        io::{self, Read},
        sync::Arc,
        thread,
    },

    bi::{Bi, Options},
};

let bi = Arc::new(Bi::from(Options {
    limit: 1024 * 1024 * 256,
    buf_size: 1024 * 64,
    wait_timeout: Duration::from_secs(10),
}));

let threads = (0..100).map(|_| {
    let bi = bi.clone();
    thread::spawn(move || {
        // For demonstration, we use io::repeat()
        let bytes = bi.read(&mut io::repeat(0).take(100), 100)?;

        // Do something with bytes...

        io::Result::Ok(())
    })
}).collect::<Vec<_>>();

for t in threads {
    if let Err(err) = t.join().unwrap() {
        eprintln!("{}", err);
    }
}

Implementations

impl Bi[src]

pub fn read<R>(&self, src: &mut R, capacity: usize) -> IoResult<Bytes> where
    R: Read
[src]

Reads into new Bytes

Capacity is used to request memory upfront. It would help if you provide a good value. If capacity is lower than real data, the function will request more memory.

Trait Implementations

impl Debug for Bi[src]

impl From<Options> for Bi[src]

Auto Trait Implementations

impl RefUnwindSafe for Bi

impl Send for Bi

impl Sync for Bi

impl Unpin for Bi

impl UnwindSafe for Bi

Blanket Implementations

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

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

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

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

impl<T, U> Into<U> for T where
    U: From<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.