libnotcurses_sys

Struct NcFile

source
pub struct NcFile { /* private fields */ }
Available on crate feature std only.
Expand description

A wrapper struct around libc::FILE

The notcursesFILE 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

§Constants

source

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.

source

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

source

pub const READ_ONLY: &'static str = "r"

Intended to be passed into the CFile::open method. It will only allow reading.

source

pub const WRITE_ONLY: &'static str = "w"

Intended to be passed into the CFile::open method. It will only allow writing.

source

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.

source

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.

source

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

§Constructors

source

pub unsafe fn from_nc(file: *mut FILE) -> Self

NcFile constructor from a file produced by notcurses.

source

pub unsafe fn from_libc(file: *mut FILE) -> Self

NcFile constructor from a file produced by the libc crate.

source§

impl NcFile

§Methods

source

pub fn as_libc_ptr(&self) -> *mut FILE

Returns the file pointer in the format expected by the libc crate.

source

pub fn as_nc_ptr(&self) -> *mut FILE

Returns the file pointer in the format expected by notcurses.

source

pub fn current_pos(&self) -> Result<u64, Error>

Returns the current position in the file.

On error Error::Errno(errno) is returned.

source

pub fn read_all(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>

Reads the file from start to end. Convenience method.

Trait Implementations§

source§

impl Debug for NcFile

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for NcFile

source§

fn drop(&mut self)

Ensures the file stream is closed before abandoning the data.

source§

impl Read for NcFile

source§

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>

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>

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>

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>

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

fn is_read_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Reader has an efficient read_vectored implementation. Read more
source§

fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Pull some bytes from this source into the specified buffer. Read more
source§

fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Reads the exact number of bytes required to fill cursor. Read more
1.0.0 · source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adaptor for this instance of Read. Read more
1.0.0 · source§

fn bytes(self) -> Bytes<Self>
where Self: Sized,

Transforms this Read instance to an Iterator over its bytes. Read more
1.0.0 · source§

fn chain<R>(self, next: R) -> Chain<Self, R>
where R: Read, Self: Sized,

Creates an adapter which will chain this stream with another. Read more
1.0.0 · source§

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

Creates an adapter which will read at most limit bytes from it. Read more
source§

impl Seek for NcFile

source§

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>

Rewind to the beginning of a stream. Read more
source§

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

🔬This is a nightly-only experimental API. (seek_stream_len)
Returns the length of this stream (in bytes). Read more
1.51.0 · source§

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

Returns the current seek position from the start of the stream. Read more
1.80.0 · source§

fn seek_relative(&mut self, offset: i64) -> Result<(), Error>

Seeks relative to the current position. Read more

Auto Trait Implementations§

§

impl Freeze for NcFile

§

impl RefUnwindSafe for NcFile

§

impl !Send for NcFile

§

impl !Sync for NcFile

§

impl Unpin for NcFile

§

impl UnwindSafe for NcFile

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.