Skip to main content

RandomAccessFile

Struct RandomAccessFile 

Source
pub struct RandomAccessFile(/* private fields */);
Expand description

A file with cross-platform positioned I/O.

Reading from this file or writing to it does not use its internal OS cursor, but it may move it anyway. This can cause surprising behaviour if shared with a File (this could be done with try_clone).

Implementations§

Source§

impl RandomAccessFile

Source

pub fn open<P: AsRef<Path>>(path: P) -> Result<RandomAccessFile>

Attempts to open a file in read-only mode.

See File::open for details.

Source

pub fn create<P: AsRef<Path>>(path: P) -> Result<RandomAccessFile>

Opens a file in write-only mode.

See File::create for details.

Source

pub fn sync_all(&self) -> Result<()>

Attempts to sync all OS-internal metadata to disk.

See File::sync_all for details.

Source

pub fn sync_data(&self) -> Result<()>

This function is similar to sync_all, except that it may not synchronize file metadata to the filesystem.

See File::sync_data for details.

Source

pub fn set_len(&self, size: u64) -> Result<()>

Truncates or extends the underlying file, updating the size of this file to become size.

See File::set_len for details.

Source

pub fn metadata(&self) -> Result<Metadata>

Queries metadata about the underlying file.

See File::metadata for details.

Source

pub fn try_clone(&self) -> Result<RandomAccessFile>

Creates a new File instance that shares the same underlying file handle as the existing File instance

See File::try_clone for details.

Source

pub fn set_permissions(&self, perm: Permissions) -> Result<()>

Changes the permissions on the underlying file.

See File::set_permissions for details.

Source

pub fn into_inner(self) -> File

Unwraps the inner File.

The file’s cursor position is unspecified.

Trait Implementations§

Source§

impl AsFd for RandomAccessFile

Available on Unix, or WASI and WASIp1 only.
Source§

fn as_fd(&self) -> BorrowedFd<'_>

Borrows the file descriptor. Read more
Source§

impl AsRawFd for RandomAccessFile

Available on Unix, or WASI and WASIp1 only.
Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl Debug for RandomAccessFile

Source§

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

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

impl From<File> for RandomAccessFile

Source§

fn from(file: File) -> RandomAccessFile

Creates a new RandomAccessFile from an open File.

Source§

impl From<OwnedFd> for RandomAccessFile

Available on Unix, or WASI and WASIp1 only.
Source§

fn from(fd: OwnedFd) -> Self

Converts to this type from the input type.
Source§

impl From<RandomAccessFile> for File

Source§

fn from(file: RandomAccessFile) -> File

Converts to this type from the input type.
Source§

impl From<RandomAccessFile> for OwnedFd

Available on Unix, or WASI and WASIp1 only.
Source§

fn from(f: RandomAccessFile) -> Self

Converts to this type from the input type.
Source§

impl From<RandomAccessFile> for SyncFile

Source§

fn from(file: RandomAccessFile) -> SyncFile

Creates a new SyncFile from an open RandomAccessFile.

The cursor starts at the beginning of the file.

Source§

impl FromRawFd for RandomAccessFile

Available on Unix, or WASI and WASIp1 only.
Source§

unsafe fn from_raw_fd(fd: RawFd) -> Self

Constructs a new instance of Self from the given raw file descriptor. Read more
Source§

impl IntoRawFd for RandomAccessFile

Available on Unix, or WASI and WASIp1 only.
Source§

fn into_raw_fd(self) -> RawFd

Consumes this object, returning the raw underlying file descriptor. Read more
Source§

impl ReadAt for RandomAccessFile

Source§

fn read_at(&self, buf: &mut [u8], offset: u64) -> Result<usize>

Reads a number of bytes starting from a given offset. Read more
Source§

fn read_exact_at(&self, buf: &mut [u8], offset: u64) -> Result<()>

Reads the exact number of byte required to fill buf from the given offset. Read more
Source§

fn read_vectored_at( &self, bufs: &mut [IoSliceMut<'_>], offset: u64, ) -> Result<usize>

Like read_at, except that it reads into a slice of buffers. Read more
Source§

impl Size for RandomAccessFile

Source§

fn size(&self) -> Result<u64>

Returns the size of the stream.
Source§

impl WriteAt for RandomAccessFile

Source§

fn write_at(&self, buf: &[u8], offset: u64) -> Result<usize>

Writes a number of bytes starting from a given offset. Read more
Source§

fn write_all_at(&self, buf: &[u8], offset: u64) -> Result<()>

Attempts to write an entire buffer starting from a given offset. Read more
Source§

fn flush(&self) -> Result<()>

Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
Source§

fn write_vectored_at(&self, bufs: &[IoSlice<'_>], offset: u64) -> Result<usize>

Like write_at, except that it writes from a slice of buffers. Read more

Auto Trait Implementations§

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.