pub struct NcFile { /* private fields */ }
std
only.Expand description
A wrapper struct around
libc::FILE
The notcurses
’ FILE
type is a transparent
struct, while the equivalent libc
’s FILE
is an opaque enum.
Several methods are provided to cast back and forth between both types,
in order to allow both rust libc operations and notcurses file operations
over the same underlying *FILE
.
Implementations§
source§impl NcFile
impl NcFile
§Constants
sourcepub const RANDOM_ACCESS_MODE: &'static str = "rb+"
pub const RANDOM_ACCESS_MODE: &'static str = "rb+"
Intended to be passed into the CFile::open method. It will open the file in a way that will allow reading and writing, including overwriting old data. It will not create the file if it does not exist.
sourcepub const UPDATE: &'static str = "rb+"
pub const UPDATE: &'static str = "rb+"
Intended to be passed into the CFile::open method. It will open the file in a way that will allow reading and writing, including overwriting old data
sourcepub const READ_ONLY: &'static str = "r"
pub const READ_ONLY: &'static str = "r"
Intended to be passed into the CFile::open method. It will only allow reading.
sourcepub const WRITE_ONLY: &'static str = "w"
pub const WRITE_ONLY: &'static str = "w"
Intended to be passed into the CFile::open method. It will only allow writing.
sourcepub const APPEND_ONLY: &'static str = "a"
pub const APPEND_ONLY: &'static str = "a"
Intended to be passed into the CFile::open method. It will only allow data to be appended to the end of the file.
sourcepub const APPEND_READ: &'static str = "a+"
pub const APPEND_READ: &'static str = "a+"
Intended to be passed into the CFile::open method. It will allow data to be appended to the end of the file, and data to be read from the file. It will create the file if it doesn’t exist.
sourcepub const TRUNCATE_RANDOM_ACCESS_MODE: &'static str = "wb+"
pub const TRUNCATE_RANDOM_ACCESS_MODE: &'static str = "wb+"
Intended to be passed into the CFile::open method. It will open the file in a way that will allow reading and writing, including overwriting old data. It will create the file if it doesn’t exist
source§impl NcFile
impl NcFile
§Methods
sourcepub fn as_libc_ptr(&self) -> *mut FILE
pub fn as_libc_ptr(&self) -> *mut FILE
Returns the file pointer in the format expected by the libc
crate.
sourcepub fn as_nc_ptr(&self) -> *mut FILE
pub fn as_nc_ptr(&self) -> *mut FILE
Returns the file pointer in the format expected by notcurses.
sourcepub fn current_pos(&self) -> Result<u64, Error>
pub fn current_pos(&self) -> Result<u64, Error>
Returns the current position in the file.
On error Error::Errno(errno)
is returned.
Trait Implementations§
source§impl Read for NcFile
impl Read for NcFile
source§fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
Reads exactly the number of bytes required to fill buf.
If the end of the file is reached before buf is filled,
Err(EndOfFile(bytes_read))
will be returned. The data that was read
before that will still have been placed into buf.
Upon some other error, Err(Errno(errno))
will be returned.
source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
Reads the entire file starting from the current_position expanding buf as needed.
On a successful read, this function will return Ok(bytes_read)
.
If an error occurs during reading, some varient of error will be returned.
source§fn read_to_string(&mut self, strbuf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, strbuf: &mut String) -> Result<usize, Error>
Reads the entire file from the beginning and stores it in a string.
On a successful read, this function will return Ok(bytes_read)
.
If an error occurs during reading, some varient of error will be returned.
source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
Reads exactly the number of bytes required to fill buf.
If the end of the file is reached before buf is filled,
Err(EndOfFile(bytes_read))
will be returned. The data that was read
before that will still have been placed into buf.
Upon some other error, Err(Errno(errno))
will be returned.
1.36.0 · source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read
, except that it reads into a slice of buffers. Read moresource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)source§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read moresource§impl Seek for NcFile
impl Seek for NcFile
source§fn seek(&mut self, pos: SeekFrom) -> Result<u64, Error>
fn seek(&mut self, pos: SeekFrom) -> Result<u64, Error>
Changes the current position in the file using the SeekFrom
enum.
To set relative to the beginning of the file (i.e. index is 0 + offset):
SeekFrom::Start(offset)
To set relative to the end of the file (i.e. index is file_lenth - 1 - offset):
SeekFrom::End(offset)
To set relative to the current position:
SeekFrom::End(offset)
On error Error::Errno(errno)
is returned.
1.55.0 · source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
source§fn stream_len(&mut self) -> Result<u64, Error>
fn stream_len(&mut self) -> Result<u64, Error>
seek_stream_len
)