[]Struct cfile::CFile

pub struct CFile(_);

A reference to an open stream on the filesystem.

An instance of a CFile can be read and/or written depending on what modes it was opened with. CFile also implement Seek to alter the logical cursor that the file contains internally.

Methods

impl CFile[src]

pub fn fdopen<S: AsRef<str>>(fd: RawFd, mode: S) -> Result<CFile>[src]

impl CFile[src]

Important traits for Unlocked
pub fn unlocked(self) -> Unlocked[src]

Returns a unlocked CFile stream except that they do not use locking.

Methods from Deref<Target = CFileRef>

pub fn reopen(&self, filename: &str, mode: &str) -> Result<CFile>[src]

opens the file whose name is the string pointed to by filename and associates the stream pointed to by stream with it.

The original stream (if it exists) is closed. The mode argument is used just as in the open() function.

Important traits for Bytes<'a>
pub fn bytes(&self) -> Bytes[src]

An iterator over the bytes of a *FILE stream.

Important traits for Lines<T>
pub fn lines(&self) -> Lines<Bytes>[src]

An iterator over the lines of a *FILE stream.

pub fn lock(&mut self) -> FileLock[src]

acquires an exclusive lock on the specified object.

If another thread has already locked the object, will block until the lock is released.

Examples

use std::io::Write;
use cfile::tmpfile;

let mut f = tmpfile().unwrap();
let mut l = f.lock();

assert_eq!(l.write(b"test").unwrap(), 4);

pub fn try_lock(&mut self) -> Option<FileLock>[src]

a non-blocking version of lock();

if the lock cannot be acquired immediately, try_lock() returns None instead of blocking.

Examples

use std::io::{Read, Write, BufRead, BufReader, Seek, SeekFrom};
use cfile::tmpfile;

let mut f = tmpfile().unwrap();

if let Some(mut c) = f.try_lock() {
    assert_eq!(c.write(b"test").unwrap(), 4);
}

assert_eq!(f.seek(SeekFrom::Start(0)).unwrap(), 0); // seek to the beginning of stream

let mut r = BufReader::new(f);
let mut s = String::new();
assert_eq!(r.read_line(&mut s).unwrap(), 4); // read back the text
assert_eq!(s, "test");

Trait Implementations

impl Send for CFile

impl AsMut<CFileRef> for CFile

impl Drop for CFile

impl AsRef<CFileRef> for CFile

impl DerefMut for CFile

impl Deref for CFile

type Target = CFileRef

The resulting type after dereferencing.

impl BorrowMut<CFileRef> for CFile

impl Borrow<CFileRef> for CFile

impl Seek for CFile[src]

fn stream_len(&mut self) -> Result<u64, Error>[src]

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

Returns the length of this stream (in bytes). Read more

fn stream_position(&mut self) -> Result<u64, Error>[src]

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

Returns the current seek position from the start of the stream. Read more

impl Write for CFile[src]

fn write_vectored(&mut self, bufs: &[IoSlice]) -> Result<usize, Error>1.36.0[src]

Like write, except that it writes from a slice of buffers. Read more

fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>1.0.0[src]

Attempts to write an entire buffer into this writer. Read more

fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>1.0.0[src]

Writes a formatted string into this writer, returning any error encountered. Read more

fn by_ref(&mut self) -> &mut Self1.0.0[src]

Creates a "by reference" adaptor for this instance of Write. Read more

impl Read for CFile[src]

fn read_vectored(&mut self, bufs: &mut [IoSliceMut]) -> Result<usize, Error>1.36.0[src]

Like read, except that it reads into a slice of buffers. Read more

unsafe fn initializer(&self) -> Initializer[src]

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

Determines if this Reader can work with buffers of uninitialized memory. Read more

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>1.0.0[src]

Read all bytes until EOF in this source, placing them into buf. Read more

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>1.0.0[src]

Read all bytes until EOF in this source, appending them to buf. Read more

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>1.6.0[src]

Read the exact number of bytes required to fill buf. Read more

fn by_ref(&mut self) -> &mut Self1.0.0[src]

Creates a "by reference" adaptor for this instance of Read. Read more

fn bytes(self) -> Bytes<Self>1.0.0[src]

Transforms this Read instance to an [Iterator] over its bytes. Read more

fn chain<R>(self, next: R) -> Chain<Self, R> where
    R: Read
1.0.0[src]

Creates an adaptor which will chain this stream with another. Read more

fn take(self, limit: u64) -> Take<Self>1.0.0[src]

Creates an adaptor which will read at most limit bytes from it. Read more

impl IntoRawFd for CFile[src]

impl ForeignType for CFile

type CType = FILE

The raw C type.

type Ref = CFileRef

The type representing a reference to this type.

Auto Trait Implementations

impl !Sync for CFile

Blanket Implementations

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

impl<T> From<T> for T[src]

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.

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

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

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