#resource #lock #stdin #pass #locked #stdin-lock #with-lock

locked-resource

Allows you to pass a lock (StdinLock) with it's resource (Stdin)

2 releases

0.1.1 May 31, 2019
0.1.0 May 31, 2019

#6 in #locked

23 downloads per month

MIT/Apache

7KB
68 lines

Allows you to pass a lock with it's resource.

use locked_resource::{LockedResource, WithLock};
use std::io::{stdin, BufRead, Stdin, StdinLock};

fn use_stdin<'l>(
    mut locked_stdin: LockedResource<Stdin, StdinLock<'l>>,
) -> LockedResource<Stdin, StdinLock<'l>> {
    let mut line = String::new();
    locked_stdin.read_line(&mut line).unwrap();
    locked_stdin
}

fn main() {
    let mut locked_stdin = stdin().with_lock();

    let mut line = String::new();
    locked_stdin.read_line(&mut line).unwrap();
    let locked_resource = use_stdin(locked_stdin);

    let mut line = String::new();
    locked_stdin.read_line(&mut line).unwrap();
}

TODO

  • Implement for Stdout
  • Implement for Stderr
  • etc..

No runtime deps