StatxBuilder

Struct StatxBuilder 

Source
pub struct StatxBuilder { /* private fields */ }
Expand description

A builder used to make a uring statx(2) call.

This builder supports the flags and mask options and can be finished with a call to statx().

See StatxBuilder::new for more details.

Implementations§

Source§

impl StatxBuilder

Source

pub fn new() -> StatxBuilder

Returns a builder to fully specify the arguments to the uring statx(2) operation.

The libc::statx structure returned in described in the statx(2) man page.

This builder defaults to having no open file descriptor and defaults flags to libc::AT_EMPTY_PATH and mask to libc::STATX_ALL.

Refer to the man page for details about the flags, mask values and returned structure, libc::statx.

§Examples
tokio_uring::start(async {
    let want_mode: u16 = 0o775;

    // Fetch file metadata
    let statx = tokio_uring::fs::StatxBuilder::new()
        .mask(libc::STATX_MODE)
        .pathname("foo.txt").unwrap()
        .statx().await.unwrap();
    let got_mode = statx.stx_mode & 0o7777;

    if want_mode == got_mode {
        println!("Success: wanted mode {want_mode:#o}, got mode {got_mode:#o}");
    } else {
        println!("Fail: wanted mode {want_mode:#o}, got mode {got_mode:#o}");
    }
})
Source

pub fn dirfd(&mut self, file: &File) -> &mut Self

Sets the dirfd option, setting or replacing the file descriptor which may be for a directory but doesn’t have to be. When used with a path, it should be a directory but when used without a path, can be any file type. So dirfd is a bit of a misnomer but it is what the statx(2) man page calls it.

§Examples
use tokio_uring::fs::{self, File};

tokio_uring::start(async {
    let dir = fs::OpenOptions::new()
        .open("/home/linux")
        .await.unwrap();

    // Fetch file metadata
    let statx = fs::StatxBuilder::new()
        .dirfd(&dir)
        .mask(libc::STATX_TYPE)
        .pathname(".cargo").unwrap()
        .statx().await.unwrap();

    dir.close().await.unwrap();
})
Source

pub fn pathname<P: AsRef<Path>>(&mut self, path: P) -> Result<&mut Self>

Sets the path option, setting or replacing the path option to the command. The path may be absolute or relative.

§Examples
use tokio_uring::fs::{self, File};

tokio_uring::start(async {
    let dir = fs::OpenOptions::new()
        .open("/home/linux")
        .await.unwrap();

    // Fetch file metadata
    let statx = fs::StatxBuilder::new()
        .dirfd(&dir)
        .pathname(".cargo").unwrap()
        .mask(libc::STATX_TYPE)
        .statx().await.unwrap();

    dir.close().await.unwrap();
})
Source

pub fn flags(&mut self, flags: i32) -> &mut Self

Sets the flags option, replacing the default.

See statx(2) for a full description of flags.

§Examples
tokio_uring::start(async {
    // Fetch file metadata
    let statx = tokio_uring::fs::StatxBuilder::new()
        .flags(libc::AT_NO_AUTOMOUNT)
        .pathname("foo.txt").unwrap()
        .statx().await.unwrap();
})
Source

pub fn mask(&mut self, mask: u32) -> &mut Self

Sets the mask option, replacing the default.

§Examples
tokio_uring::start(async {
    // Fetch file metadata
    let statx = tokio_uring::fs::StatxBuilder::new()
        .mask(libc::STATX_BASIC_STATS)
        .pathname("foo.txt").unwrap()
        .statx().await.unwrap();
})
Source

pub async fn statx(&mut self) -> Result<statx>

Returns the metadata requested for the optional open file. If no open file was provided, the metadata for the current working directory is returned.

§Examples
use tokio_uring::fs::{self, File};

tokio_uring::start(async {
    let dir = fs::OpenOptions::new()
        .open("/home/linux")
        .await.unwrap();

    // Fetch file metadata
    let statx = fs::StatxBuilder::new()
        .dirfd(&dir)
        .pathname(".cargo").unwrap()
        .mask(libc::STATX_TYPE)
        .statx().await.unwrap();

    dir.close().await.unwrap();
})

Trait Implementations§

Source§

impl Default for StatxBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.