[−][src]Struct bi::FileBi
File Bi
Helps reading/writing files synchronously.
Examples
use std::{ path::PathBuf, sync::Arc, thread, time::Duration, }; use bi::{Bi, FileBi}; let max_buf_size = 1024 * 1024; let delay = Duration::from_millis(100); let timeout = 30; let file_bi = Arc::new(FileBi::new(max_buf_size, Some(delay), Some(timeout))); let job = { let file_bi = file_bi.clone(); thread::spawn(move || { let file = &PathBuf::from(file!()).canonicalize().unwrap(); let (id, bytes) = file_bi.read(file).unwrap(); assert_eq!(file_bi.buf_size(), bytes.len() as u64); file_bi.release_read(id).unwrap(); file_bi.release_read(id).unwrap_err(); }) }; job.join().unwrap(); assert_eq!(file_bi.buf_size(), 0);
Methods
impl<'_> FileBi<'_>[src]
pub const DEFAULT_DELAY: Duration[src]
pub const DEFAULT_TIMEOUT: u64[src]
pub fn new(
max_buf_size: u64,
delay: Option<Duration>,
timeout: Option<u64>
) -> Self[src]
max_buf_size: u64,
delay: Option<Duration>,
timeout: Option<u64>
) -> Self
Makes new instance
- Delay and timeout are only used for reads. Timeout is in seconds. When buf size reaches max buf size, next reads will have to wait for
your processing code. When you finish handling your data, even if you call
::drop()on it, you still have to call::release_read(). Otherwise you won't be able to read next files. - Reads/writes use same lock.
Trait Implementations
impl<'a> Bi for FileBi<'a>[src]
type Resource = &'a Path
Resource
fn max_buf_size(&self) -> u64[src]
fn buf_size(&self) -> u64[src]
fn read(&self, file: Self::Resource) -> Result<(usize, Vec<u8>)>[src]
fn read_to_string(&self, file: Self::Resource) -> Result<(usize, String)>[src]
fn release_read(&self, id: usize) -> Result<()>[src]
fn write<B: AsRef<[u8]>>(&self, bytes: B, file: Self::Resource) -> Result<()>[src]
impl<'a> Debug for FileBi<'a>[src]
Auto Trait Implementations
Blanket Implementations
impl<T> From for T[src]
impl<T, U> Into for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom for T where
U: Into<T>, [src]
U: Into<T>,
type Error = !
🔬 This is a nightly-only experimental API. (
try_from)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T> Borrow for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T, U> TryInto for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,