[][src]Struct glommio::io::BufferedFile

pub struct BufferedFile { /* fields omitted */ }

Constructs a file that is backed by the operating system page cache

Implementations

impl BufferedFile[src]

pub fn is_same(&self, other: &BufferedFile) -> bool[src]

Returns true if the BufferedFile represent the same file on the underlying device.

Files are considered to be the same if they live in the same file system and have the same Linux inode. Note that based on this rule a symlink is not considered to be the same file.

Files will be considered to be the same if:

  • A file is opened multiple times (different file descriptors, but same file!)
  • they are hard links.

Examples

use glommio::LocalExecutor;
use glommio::io::BufferedFile;
use std::os::unix::io::AsRawFd;

let ex = LocalExecutor::make_default();
ex.run(async {
    let mut wfile = BufferedFile::create("myfile.txt").await.unwrap();
    let mut rfile = BufferedFile::open("myfile.txt").await.unwrap();
    // Different objects (OS file descriptors), so they will be different...
    assert_ne!(wfile.as_raw_fd(), rfile.as_raw_fd());
    // However they represent the same object.
    assert!(wfile.is_same(&rfile));
    wfile.close().await;
    rfile.close().await;
});

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

Similar to create in the standard library, but returns a BufferedFile

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

Similar to open in the standard library, but returns a BufferedFile

pub async fn write_at<'_>(&'_ self, buf: Vec<u8>, pos: u64) -> Result<usize>[src]

Write the data in the buffer buf to this BufferedFile at the specified position

This method acquires ownership of the buffer so the buffer can be kept alive while the kernel has it.

Note that it is legal to return fewer bytes than the buffer size. That is the situation, for example, when the device runs out of space (See the man page for write(2) for details)

Examples

use glommio::LocalExecutor;
use glommio::io::BufferedFile;

let ex = LocalExecutor::make_default();
ex.run(async {
    let file = BufferedFile::create("test.txt").await.unwrap();

    let mut buf = vec![0, 1, 2, 3];
    file.write_at(buf, 0).await.unwrap();
    file.close().await.unwrap();
});

pub async fn read_at<'_>(&'_ self, pos: u64, size: usize) -> Result<Vec<u8>>[src]

Reads data at the specified position into the user-provided buffer buf.

Note that this differs from DmaFile's read APIs: that reflects the fact that buffered reads need no specific alignment and io_uring will not be able to use its own pre-allocated buffers for it anyway.

pub async fn fdatasync<'_>(&'_ self) -> Result<()>[src]

Issues fdatasync into the underlying file.

pub async fn pre_allocate<'_>(&'_ self, size: u64) -> Result<()>[src]

pre-allocates space in the filesystem to hold a file at least as big as the size argument

pub async fn truncate<'_>(&'_ self, size: u64) -> Result<()>[src]

Truncates a file to the specified size.

Warning: synchronous operation, will block the reactor

pub async fn rename<P: AsRef<Path>, '_>(&'_ mut self, new_path: P) -> Result<()>[src]

rename this file.

Warning: synchronous operation, will block the reactor

pub async fn remove<'_>(&'_ self) -> Result<()>[src]

remove this file

The file does not have to be closed to be removed. Removing removes the name from the filesystem but the file will still be accessible for as long as it is open.

Warning: synchronous operation, will block the reactor

pub async fn file_size<'_>(&'_ self) -> Result<u64>[src]

Returns the size of a file, in bytes

pub async fn close(self) -> Result<()>[src]

Closes this file.

Trait Implementations

impl AsRawFd for BufferedFile[src]

impl Debug for BufferedFile[src]

impl FromRawFd for BufferedFile[src]

Auto Trait Implementations

Blanket Implementations

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

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

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

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.