Struct File
pub struct File { /* private fields */ }
Expand description
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. The File
type provides positional read and write
operations. The file does not maintain an internal cursor. The caller is
required to specify an offset when issuing an operation.
While files are automatically closed when they go out of scope, the
operation happens asynchronously in the background. It is recommended to
call the close()
function in order to guarantee that the file successfully
closed before exiting the scope. Closing a file does not guarantee writes
have persisted to disk. Use sync_all
to ensure all writes have reached
the filesystem.
ยงExamples
Creates a new file and write data to it:
use tokio_uring::fs::File;
fn main() -> Result<(), Box<dyn std::error::Error>> {
tokio_uring::start(async {
// Open a file
let file = File::create("hello.txt").await?;