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
impl StatxBuilder
Sourcepub fn new() -> StatxBuilder
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}");
}
})Sourcepub fn dirfd(&mut self, file: &File) -> &mut Self
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();
})Sourcepub fn pathname<P: AsRef<Path>>(&mut self, path: P) -> Result<&mut Self>
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();
})Sourcepub fn flags(&mut self, flags: i32) -> &mut Self
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();
})Sourcepub fn mask(&mut self, mask: u32) -> &mut Self
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();
})Sourcepub async fn statx(&mut self) -> Result<statx>
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();
})