Struct bi::Bi [−][src]
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]
R: Read,
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
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,