Crates.io | xattrs |
lib.rs | xattrs |
version | 0.1.0 |
source | src |
created_at | 2025-05-26 12:51:15.803799+00 |
updated_at | 2025-05-26 12:51:15.803799+00 |
description | Cross-platform xattr support. |
homepage | |
repository | https://git.mooli.net/pndc/xattrs-rs |
max_upload_size | |
id | 1689538 |
size | 112,395 |
This crate provides a cross-platform way to access xattrs. If you are unfamiliar with xattrs, a
general overview can be found in [manual
]. The supported platforms are currently Linux, NetBSD,
FreeBSD and MacOS.
Normally you will only be interested in user xattrs. There is a high-level API in [user
] which
includes extension traits that add xattr-related operations to paths and file descriptors:
use std::path::Path;
use xattrs::PathExt as _;
fn dump_xattrs(path: &Path) -> xattrs::Result<()> {
let xattrs = path.read_xattrs()?; // Reading attribute list can fail on I/O
for kv in &xattrs {
let (name, value) = kv?; // reading an attribute can fail on I/O
println!("{name:?} -> {value:?}");
}
Ok(())
}
For advanced use, such as operations on non-user xattrs, or where you want to minimise allocations
and copies, there is the "plumbing" module [pb
]. Note that non-user xattrs tend to be very
platform specific and so your code will not be directly portable without
#[cfg(target_os=…)]
. The benefit of this crate in such cases is mainly to provide a
safe checked API atop the underlying unsafe libc calls.
There is also an xattr
crate. I started writing (but did not release) xattrs
before that one was
released, but have decided to release this anyway as it has a lot more functionality and supports
more platforms, and automatically handles prepending "user." to xattr names on Linux but omits it on
other platforms. However, if you are happy with xattr
then there's no need to switch.