Crate cfile

Source
Expand description

Rust bindings to C *FILE stream

§Examples

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");

Modules§

unlocked
Each of these functions has the same behavior as its counterpart without the “_unlocked” suffix, except that they do not use locking (they do not set locks themselves, and do not test for the presence of locks set by others) and hence are thread-unsafe.

Structs§

Bytes
An iterator over the bytes of a *FILE stream.
CFile
A reference to an open stream on the filesystem.
CFileRef
A borrowed reference to a CFile.
FileLock
A locked reference to the CFile stream.
Lines
An iterator over the lines of a *FILE stream.

Traits§

AsStream
A trait for converting a raw fd to a C *FILE stream.
IntoStream
A trait to express the ability to consume an object and acquire ownership of its stream.
Stream
The C *FILE stream

Functions§

fdopen
associates a stream with the existing file descriptor.
open
opens the file whose name is the string pointed to by filename and associates a stream with it.
stderr
open stderr as a write only stream
stdin
open stdin as a read only stream
stdout
open stdout as a write only stream
tmpfile
open a temporary file as a read/write stream