[−]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 Send for CFile
impl Drop for CFile
fn drop(&mut self)
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 Borrow<CFileRef> for CFile
impl BorrowMut<CFileRef> for CFile
ⓘImportant traits for CFileReffn borrow_mut(&mut self) -> &mut CFileRef
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]
unsafe fn initializer(&self) -> Initializer
[src]
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
1.0.0[src]
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0[src]
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
1.6.0[src]
fn by_ref(&mut self) -> &mut Self
1.0.0[src]
fn bytes(self) -> Bytes<Self>
1.0.0[src]
fn chain<R>(self, next: R) -> Chain<Self, R> where
R: Read,
1.0.0[src]
R: Read,
fn take(self, limit: u64) -> Take<Self>
1.0.0[src]
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]
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
1.0.0[src]
fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>
1.0.0[src]
fn by_ref(&mut self) -> &mut Self
1.0.0[src]
impl Seek for CFile
[src]
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
[src]
fn stream_len(&mut self) -> Result<u64, Error>
[src]
fn stream_position(&mut self) -> Result<u64, Error>
[src]
impl IntoRawFd for CFile
[src]
fn into_raw_fd(self) -> RawFd
[src]
impl ForeignType for CFile
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
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> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,