https://github.com/flier/rust-cfile
Rust bindings to C FILE stream
https://github.com/flier/rust-cfile
Last synced: over 1 year ago
JSON representation
Rust bindings to C FILE stream
- Host: GitHub
- URL: https://github.com/flier/rust-cfile
- Owner: flier
- Created: 2016-04-29T11:27:09.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2019-11-07T08:00:29.000Z (over 6 years ago)
- Last Synced: 2025-03-24T07:14:23.599Z (over 1 year ago)
- Language: Rust
- Size: 1.21 MB
- Stars: 8
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# rust-cfile [](https://crates.io/crates/cfile) [](https://docs.rs/crate/cfile/) [](https://travis-ci.org/flier/rust-cfile) [](https://ci.appveyor.com/project/flier/rust-cfile) [](https://deps.rs/repo/github/flier/rust-cfile)
Rust bindings to C *FILE stream
## Examples
```rust
use std::io::prelude::*;
use std::io::{BufReader, SeekFrom};
use cfile;
// open a tempfile
let mut f = cfile::tmpfile().unwrap();
// write something to the stream
assert_eq!(f.write(b"test").unwrap(), 4);
// force to flush the stream
f.flush().unwrap();
// seek to the beginning of stream
assert_eq!(f.seek(SeekFrom::Start(0)).unwrap(), 0);
let mut r = BufReader::new(f);
let mut s = String::new();
// read back the text
assert_eq!(r.read_line(&mut s).unwrap(), 4);
assert_eq!(s, "test");
```