pub struct Bi { /* private fields */ }
Expand description
§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§
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Bi
impl RefUnwindSafe for Bi
impl Send for Bi
impl Sync for Bi
impl Unpin for Bi
impl UnwindSafe for Bi
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more