https://github.com/avi-d-coder/locked-resource
Allows you to pass a lock (StdinLock) with it's resource (Stdin).
https://github.com/avi-d-coder/locked-resource
Last synced: 9 months ago
JSON representation
Allows you to pass a lock (StdinLock) with it's resource (Stdin).
- Host: GitHub
- URL: https://github.com/avi-d-coder/locked-resource
- Owner: Avi-D-coder
- License: apache-2.0
- Created: 2019-05-31T10:58:54.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-06-17T22:12:41.000Z (over 6 years ago)
- Last Synced: 2025-03-03T06:04:32.001Z (10 months ago)
- Language: Rust
- Size: 6.84 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
Allows you to pass a lock with it's resource.
```rust
use locked_resource::{LockedResource, WithLock};
use std::io::{stdin, BufRead, Stdin, StdinLock};
fn use_stdin<'l>(
mut locked_stdin: LockedResource>,
) -> LockedResource> {
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..