pub struct File { /* private fields */ }Expand description
An asynchronous file handle backed by either a remote VFS client or the local process.
File handles implement Tokio’s asynchronous read, write, and seek traits.
Clones share one open file, as duplicated descriptors do: one cursor
position, one set of locks, and one closed state. Closing or handing off
the file through any clone closes it for all of them, and their later
operations fail with ErrorKind::Closed. Operations in flight are not
shared: a clone starts with none, and its reads and writes do not wait for
another clone’s.
Implementations§
Source§impl File
impl File
Sourcepub fn poll_read_uninit(
&mut self,
cx: &mut Context<'_>,
buf: &mut [MaybeUninit<u8>],
) -> Poll<Result<usize>>
pub fn poll_read_uninit( &mut self, cx: &mut Context<'_>, buf: &mut [MaybeUninit<u8>], ) -> Poll<Result<usize>>
Reads at the cursor into uninitialized storage, returning how many
bytes at its front were filled. Zero means end of file, unless buf
is empty.
This is [AsyncRead::poll_read] without the requirement that buf be
initialized, so a caller reading into fresh memory need not zero it
first. The remote backend writes the reply straight into buf.
Source§impl File
impl File
Sourcepub async fn close(self) -> Result<()>
pub async fn close(self) -> Result<()>
Closes the file, for every clone. Closing a closed file does nothing.
Sourcepub fn read_at<'b>(
&self,
buf: &'b mut BytesMut,
offset: u64,
) -> impl Future<Output = Result<usize>> + Send + use<'b>
pub fn read_at<'b>( &self, buf: &'b mut BytesMut, offset: u64, ) -> impl Future<Output = Result<usize>> + Send + use<'b>
Reads into buf’s spare capacity starting at offset, returning the
transfer count.
Cancelling the read may leave buf empty.
Fewer bytes than the spare capacity available may be read. 0 indicates
either end-of-file or that buf had no spare capacity.
Sourcepub fn write_at(
&self,
data: Bytes,
offset: u64,
) -> impl Future<Output = Result<usize>> + Send + use<>
pub fn write_at( &self, data: Bytes, offset: u64, ) -> impl Future<Output = Result<usize>> + Send + use<>
Writes data at offset, returning the byte count.
May write less than all of data on success, but at least 1 byte unless data is empty.
Use on an append-mode handle is an error; use append there.
Sourcepub fn append(
&self,
data: Bytes,
) -> impl Future<Output = Result<(usize, u64)>> + Send + use<>
pub fn append( &self, data: Bytes, ) -> impl Future<Output = Result<(usize, u64)>> + Send + use<>
Appends data, returning the byte count and the position just past
what was written. Less data may be written than requested on success,
but at least 1 byte will be written unless data was empty.
Sourcepub fn read_at_into<'b>(
&self,
buf: &'b mut [MaybeUninit<u8>],
offset: u64,
) -> impl Future<Output = Result<usize>> + Send + use<'b>
pub fn read_at_into<'b>( &self, buf: &'b mut [MaybeUninit<u8>], offset: u64, ) -> impl Future<Output = Result<usize>> + Send + use<'b>
Reads into the possibly uninitialized `buf``, returning how many bytes at its front were filled.
Sourcepub fn write_at_from<'b>(
&self,
data: &'b [u8],
offset: u64,
) -> impl Future<Output = Result<usize>> + Send + use<'b>
pub fn write_at_from<'b>( &self, data: &'b [u8], offset: u64, ) -> impl Future<Output = Result<usize>> + Send + use<'b>
Writes data at offset from borrowed storage, returning the byte
count.
Less data may be written than requested on success, but always at least 1
byte unless data is empty.
Sourcepub async fn copy_data(
&self,
dst: &File,
src_offset: u64,
target: CopyDest,
len: Option<u64>,
mode: CopyMode,
) -> Result<CopyDataResult>
pub async fn copy_data( &self, dst: &File, src_offset: u64, target: CopyDest, len: Option<u64>, mode: CopyMode, ) -> Result<CopyDataResult>
Copies at most 2 MiB from this file into dst.
len of None copies toward end of source. A positive result may be
short for any reason; callers that want a complete operation must loop.
Zero indicates end of source (or an empty request).
Nothing is promised about physical allocation: an accelerated route may preserve holes, and the fallback does not.
Sourcepub async fn sync(&self, data: bool) -> Result<()>
pub async fn sync(&self, data: bool) -> Result<()>
Flushes the file’s written data to durable storage, returning once the device reports it committed.
data selects a data-only flush (fdatasync), which may skip metadata
the caller does not need — notably the modification time — and so can
avoid a second write to the inode. Size changes are still flushed,
since a reader could not find the data without them.
This durably places the contents. It says nothing about the directory entry naming the file, which is a separate inode and needs its own flush to survive a crash.
Sourcepub async fn fs_metadata(&self) -> Result<FsMetadata>
pub async fn fs_metadata(&self) -> Result<FsMetadata>
Returns metadata for the filesystem containing the open file.
Sourcepub async fn acl(&self, kind: AclKind, default: bool) -> Result<Option<Acl>>
pub async fn acl(&self, kind: AclKind, default: bool) -> Result<Option<Acl>>
Returns the ACL of the requested kind. For a POSIX ACL, default
selects the directory’s default ACL rather than its access ACL; it
must be false for AclKind::Nfs4.
Sourcepub async fn set_acl(
&self,
kind: AclKind,
acl: Option<&Acl>,
default: bool,
) -> Result<()>
pub async fn set_acl( &self, kind: AclKind, acl: Option<&Acl>, default: bool, ) -> Result<()>
Sets or removes the ACL of kind. acl, if present, must match
kind. default selects the POSIX default ACL, as in
acl; it must be false for AclKind::Nfs4.
Sourcepub async fn sec_desc(&self, mask: SecInfo) -> Result<SecDesc>
pub async fn sec_desc(&self, mask: SecInfo) -> Result<SecDesc>
Returns the Windows security descriptor selected by mask.
Sourcepub async fn update_sec_desc(&self, sec_desc: &SecDesc) -> Result<()>
pub async fn update_sec_desc(&self, sec_desc: &SecDesc) -> Result<()>
Replaces the Windows security descriptor.
Sourcepub async fn xattrs(
&self,
namespace: XattrNamespace<'_>,
) -> Result<Vec<XattrEntry>>
pub async fn xattrs( &self, namespace: XattrNamespace<'_>, ) -> Result<Vec<XattrEntry>>
Lists extended attributes in namespace.
Sourcepub async fn xattr(
&self,
name: &str,
namespace: Option<&str>,
) -> Result<Vec<u8>>
pub async fn xattr( &self, name: &str, namespace: Option<&str>, ) -> Result<Vec<u8>>
Reads one extended attribute.
Sourcepub async fn streams(&self) -> Result<Vec<StreamEntry>>
pub async fn streams(&self) -> Result<Vec<StreamEntry>>
Lists alternate data streams.
Sourcepub async fn set_xattr(
&self,
name: &str,
namespace: Option<&str>,
value: &[u8],
) -> Result<()>
pub async fn set_xattr( &self, name: &str, namespace: Option<&str>, value: &[u8], ) -> Result<()>
Creates or replaces an extended attribute.
Sourcepub async fn remove_xattr(
&self,
name: &str,
namespace: Option<&str>,
) -> Result<()>
pub async fn remove_xattr( &self, name: &str, namespace: Option<&str>, ) -> Result<()>
Removes an extended attribute.
Sourcepub async fn lock(
&self,
range: FileLockRange,
mode: FileLockMode,
behavior: FileLockBehavior,
) -> Result<Option<FileLock>>
pub async fn lock( &self, range: FileLockRange, mode: FileLockMode, behavior: FileLockBehavior, ) -> Result<Option<FileLock>>
Acquires a byte-range lock with the requested mode and behavior.
Sourcepub async fn try_into_std(self) -> Result<File, Self>
pub async fn try_into_std(self) -> Result<File, Self>
Converts this handle into a local standard-library file when possible, taking it from every clone.
Surrendering the descriptor means surrendering the cursor with it, so the file comes back positioned where this handle is.
Trait Implementations§
Source§impl AsyncRead for File
impl AsyncRead for File
Source§impl AsyncWrite for File
impl AsyncWrite for File
Source§fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
Each write reaches the file when it completes, so there is nothing buffered to push; flushing only has to settle work in flight.
Source§fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
Only flushes: the file is closed by File::close, or when dropped.
Auto Trait Implementations§
impl !RefUnwindSafe for File
impl !UnwindSafe for File
impl Freeze for File
impl Send for File
impl Sync for File
impl Unpin for File
impl UnsafeUnpin for File
Blanket Implementations§
§impl<R> AsyncReadExt for Rwhere
R: AsyncRead + ?Sized,
impl<R> AsyncReadExt for Rwhere
R: AsyncRead + ?Sized,
§fn chain<R>(self, next: R) -> Chain<Self, R>where
Self: Sized,
R: AsyncRead,
fn chain<R>(self, next: R) -> Chain<Self, R>where
Self: Sized,
R: AsyncRead,
§fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self> ⓘwhere
Self: Unpin,
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self> ⓘwhere
Self: Unpin,
buf in asynchronous
manner, returning a future type. Read more§fn read_vectored<'a>(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>],
) -> ReadVectored<'a, Self> ⓘwhere
Self: Unpin,
fn read_vectored<'a>(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>],
) -> ReadVectored<'a, Self> ⓘwhere
Self: Unpin,
AsyncRead into bufs using vectored
IO operations. Read more§fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self> ⓘwhere
Self: Unpin,
fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self> ⓘwhere
Self: Unpin,
buf,
returning an error if end of file (EOF) is hit sooner. Read more§fn read_to_end<'a>(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self> ⓘwhere
Self: Unpin,
fn read_to_end<'a>(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self> ⓘwhere
Self: Unpin,
AsyncRead. Read more§fn read_to_string<'a>(
&'a mut self,
buf: &'a mut String,
) -> ReadToString<'a, Self> ⓘwhere
Self: Unpin,
fn read_to_string<'a>(
&'a mut self,
buf: &'a mut String,
) -> ReadToString<'a, Self> ⓘwhere
Self: Unpin,
AsyncRead. Read more§impl<S> AsyncSeekExt for Swhere
S: AsyncSeek + ?Sized,
impl<S> AsyncSeekExt for Swhere
S: AsyncSeek + ?Sized,
§fn seek(&mut self, pos: SeekFrom) -> Seek<'_, Self> ⓘwhere
Self: Unpin,
fn seek(&mut self, pos: SeekFrom) -> Seek<'_, Self> ⓘwhere
Self: Unpin,
§fn stream_position(&mut self) -> Seek<'_, Self> ⓘwhere
Self: Unpin,
fn stream_position(&mut self) -> Seek<'_, Self> ⓘwhere
Self: Unpin,
§impl<W> AsyncWriteExt for Wwhere
W: AsyncWrite + ?Sized,
impl<W> AsyncWriteExt for Wwhere
W: AsyncWrite + ?Sized,
§fn flush(&mut self) -> Flush<'_, Self> ⓘwhere
Self: Unpin,
fn flush(&mut self) -> Flush<'_, Self> ⓘwhere
Self: Unpin,
AsyncWrite. Read more§fn close(&mut self) -> Close<'_, Self> ⓘwhere
Self: Unpin,
fn close(&mut self) -> Close<'_, Self> ⓘwhere
Self: Unpin,
AsyncWrite.§fn write<'a>(&'a mut self, buf: &'a [u8]) -> Write<'a, Self> ⓘwhere
Self: Unpin,
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Write<'a, Self> ⓘwhere
Self: Unpin,
buf into the object. Read more§fn write_vectored<'a>(
&'a mut self,
bufs: &'a [IoSlice<'a>],
) -> WriteVectored<'a, Self> ⓘwhere
Self: Unpin,
fn write_vectored<'a>(
&'a mut self,
bufs: &'a [IoSlice<'a>],
) -> WriteVectored<'a, Self> ⓘwhere
Self: Unpin,
bufs into the object using vectored
IO operations. Read more§fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> WriteAll<'a, Self> ⓘwhere
Self: Unpin,
fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> WriteAll<'a, Self> ⓘwhere
Self: Unpin,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FuturesAsyncReadCompatExt for Twhere
T: AsyncRead,
impl<T> FuturesAsyncReadCompatExt for Twhere
T: AsyncRead,
§impl<T> FuturesAsyncWriteCompatExt for Twhere
T: AsyncWrite,
impl<T> FuturesAsyncWriteCompatExt for Twhere
T: AsyncWrite,
§fn compat_write(self) -> Compat<Self>where
Self: Sized,
fn compat_write(self) -> Compat<Self>where
Self: Sized,
self with a compatibility layer that implements
tokio::io::AsyncWrite.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more