pub trait File: Sized {
// Required methods
fn open<'async_trait, P>(
path: P,
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
where P: 'async_trait + AsRef<Path> + Send,
Self: 'async_trait;
fn create<'async_trait, P>(
path: P,
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
where P: 'async_trait + AsRef<Path> + Send,
Self: 'async_trait;
fn sync_all<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn sync_data<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn set_len<'life0, 'async_trait>(
&'life0 self,
size: u64,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn metadata<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Metadata>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn set_permissions<'life0, 'async_trait>(
&'life0 self,
perm: Permissions,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
An async abstraction over std::fs::File.
Required Methods§
Sourcefn open<'async_trait, P>(
path: P,
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
fn open<'async_trait, P>( path: P, ) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
Opens a file in read-only mode.
See the OpenOptions::open function for more options.
§Errors
An error will be returned in the following situations:
pathdoes not point to an existing file.- The current process lacks permissions to read the file.
- Some other I/O error occurred.
For more details, see the list of errors documented by OpenOptions::open.
Sourcefn create<'async_trait, P>(
path: P,
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
fn create<'async_trait, P>( path: P, ) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
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 options.
§Errors
An error will be returned in the following situations:
- The file’s parent directory does not exist.
- The current process lacks permissions to write to the file.
- Some other I/O error occurred.
For more details, see the list of errors documented by OpenOptions::open.
Sourcefn sync_all<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn sync_all<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Synchronizes OS-internal buffered contents and metadata to disk.
This function will ensure that all in-memory data reaches the filesystem.
This can be used to handle errors that would otherwise only be caught when the file is closed. When a file is dropped, errors in synchronizing this in-memory data are ignored.
Sourcefn sync_data<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn sync_data<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Synchronizes OS-internal buffered contents to disk.
This is similar to sync_all, except that file metadata may not be synchronized.
This is intended for use cases that must synchronize the contents of the file, but don’t need the file metadata synchronized to disk.
Note that some platforms may simply implement this in terms of sync_all.
Sourcefn set_len<'life0, 'async_trait>(
&'life0 self,
size: u64,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn set_len<'life0, 'async_trait>(
&'life0 self,
size: u64,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Truncates or extends the file.
If size is less than the current file size, then the file will be truncated. If it is
greater than the current file size, then the file will be extended to size and have all
intermediate data filled with zeros.
The file’s cursor stays at the same position, even if the cursor ends up being past the end of the file after this operation.
Sourcefn metadata<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Metadata>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn metadata<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Metadata>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Reads the file’s metadata.
Sourcefn set_permissions<'life0, 'async_trait>(
&'life0 self,
perm: Permissions,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn set_permissions<'life0, 'async_trait>(
&'life0 self,
perm: Permissions,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Changes the permissions on the file.
§Errors
An error will be returned in the following situations:
- The current process lacks permissions to change attributes on the file.
- Some other I/O error occurred.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl File for File
Available on crate feature async-std-rt only.
impl File for File
async-std-rt only.fn open<'async_trait, P>( path: P, ) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
fn create<'async_trait, P>( path: P, ) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
fn sync_all<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn sync_data<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn set_len<'life0, 'async_trait>(
&'life0 self,
size: u64,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn metadata<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Metadata>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn set_permissions<'life0, 'async_trait>(
&'life0 self,
perm: Permissions,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§impl File for File
Available on crate feature tokio-rt only.
impl File for File
tokio-rt only.fn open<'async_trait, P>( path: P, ) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
fn create<'async_trait, P>( path: P, ) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
fn sync_all<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn sync_data<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn set_len<'life0, 'async_trait>(
&'life0 self,
size: u64,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn metadata<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Metadata>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn set_permissions<'life0, 'async_trait>(
&'life0 self,
perm: Permissions,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Implementors§
impl File for TokioCompat<File>
tokio-rt only.