[][src]Struct bi::FileBi

pub struct FileBi<'a> { /* fields omitted */ }

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]

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

impl<'a> Debug for FileBi<'a>[src]

Auto Trait Implementations

impl<'a> Send for FileBi<'a>

impl<'a> Sync for FileBi<'a>

Blanket Implementations

impl<T> From for T[src]

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

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

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

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

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

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.