[][src]Struct sgx_tstd::untrusted::fs::File

pub struct File { /* fields omitted */ }

A reference to an open file on the filesystem.

An instance of a File can be read and/or written depending on what options it was opened with. Files also implement Seek to alter the logical cursor that the file contains internally.

Files are automatically closed when they go out of scope. Errors detected on closing are ignored by the implementation of Drop. Use the method [sync_all] if these errors must be manually handled.


impl File[src]

pub fn open<P: AsRef<Path>>(path: P) -> Result<File>[src]

Attempts to open a file in read-only mode.

See the OpenOptions::open method for more details.


This function will return an error if path does not already exist. Other errors may also be returned according to OpenOptions::open.

pub fn create<P: AsRef<Path>>(path: P) -> Result<File>[src]

Opens a file in write-only mode.

This function will create a file if it does not exist, and will truncate it if it does.

See the OpenOptions::open function for more details.

pub fn with_options() -> OpenOptions[src]

Returns a new OpenOptions object.

This function returns a new OpenOptions object that you can use to open or create a file with specific options if open() or create() are not appropriate.

It is equivalent to OpenOptions::new() but allows you to write more readable code. Instead of OpenOptions::new().read(true).open("foo.txt") you can write File::with_options().read(true).open("foo.txt"). This also avoids the need to import OpenOptions.

See the OpenOptions::new function for more details.

pub fn sync_all(&self) -> Result<()>[src]

Attempts to sync all OS-internal metadata to disk.

This function will attempt to ensure that all in-memory data reaches the filesystem before returning.

This can be used to handle errors that would otherwise only be caught when the File is closed. Dropping a file will ignore errors in synchronizing this in-memory data.

pub fn sync_data(&self) -> Result<()>[src]

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

This is intended for use cases that must synchronize content, but don't need the metadata on disk. The goal of this method is to reduce disk operations.

Note that some platforms may simply implement this in terms of sync_all.

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

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

If the size is less than the current file's size, then the file will be shrunk. If it is greater than the current file's size, then the file will be extended to size and have all of the intermediate data filled in with 0s.

The file's cursor isn't changed. In particular, if the cursor was at the end and the file is shrunk using this operation, the cursor will now be past the end.


This function will return an error if the file is not opened for writing. Also, std::io::ErrorKind::InvalidInput will be returned if the desired length would cause an overflow due to the implementation specifics.

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

Queries metadata about the underlying file.

pub fn try_clone(&self) -> Result<File>[src]

Creates a new File instance that shares the same underlying file handle as the existing File instance. Reads, writes, and seeks will affect both File instances simultaneously.

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

Changes the permissions on the underlying file.

Platform-specific behavior

This function currently corresponds to the fchmod function on Unix and the SetFileInformationByHandle function on Windows. Note that, this may change in the future.


This function will return an error if the user lacks permission change attributes on the underlying file. It may also return an error in other os-specific unspecified cases.

Trait Implementations

impl AsRawFd for File[src]

impl Debug for File[src]

impl FileExt for File[src]

impl FromRawFd for File[src]

impl IntoRawFd for File[src]

impl Read for File[src]

impl<'_> Read for &'_ File[src]

impl Seek for File[src]

impl<'_> Seek for &'_ File[src]

impl Write for File[src]

impl<'_> Write for &'_ File[src]

Auto Trait Implementations

impl RefUnwindSafe for File

impl Send for File

impl Sync for File

impl Unpin for File

impl UnwindSafe for File

Blanket Implementations

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

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

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

impl<T> From<T> for T[src]

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.