[−]Struct cfile::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]
impl CFile[src]
ⓘImportant traits for Unlockedpub 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 Drop for CFile
fn drop(&mut self)
impl Send for CFile
impl AsRef<CFileRef> for CFile
impl AsMut<CFileRef> for CFile
impl Deref for CFile
type Target = CFileRef
The resulting type after dereferencing.
ⓘImportant traits for CFileReffn deref(&self) -> &CFileRef
impl DerefMut for CFile
impl BorrowMut<CFileRef> for CFile
ⓘImportant traits for CFileReffn borrow_mut(&mut self) -> &mut CFileRef
impl Borrow<CFileRef> for CFile
impl Write for CFile[src]
fn write(&mut self, buf: &[u8]) -> Result<usize>[src]
fn flush(&mut self) -> Result<()>[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 Seek for CFile[src]
fn seek(&mut self, pos: SeekFrom) -> Result<u64>[src]
fn stream_len(&mut self) -> Result<u64, Error>[src]
seek_convenience)Returns the length of this stream (in bytes). Read more
fn stream_position(&mut self) -> Result<u64, Error>[src]
seek_convenience)Returns the current seek position from the start of the stream. Read more
impl Read for CFile[src]
fn read(&mut self, buf: &mut [u8]) -> Result<usize>[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]
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]
R: Read,
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]
fn into_raw_fd(self) -> RawFd[src]
impl ForeignType for CFile
Auto Trait Implementations
Blanket Implementations
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,