[]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 Drop for CFile

impl AsRef<CFileRef> for CFile

impl AsMut<CFileRef> for CFile

impl Deref for CFile

type Target = CFileRef

The resulting type after dereferencing.

impl DerefMut for CFile

impl Borrow<CFileRef> for CFile

impl BorrowMut<CFileRef> for CFile

impl Read for CFile[src]

impl Write for CFile[src]

impl Seek for CFile[src]

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

impl Unpin for CFile

impl UnwindSafe for CFile

impl RefUnwindSafe 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> Borrow<T> for T where
    T: ?Sized
[src]

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

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