pub struct Xattrs(/* private fields */);Expand description
A sorted set of extended attributes, in canonical form.
Equal sets hold equal bytes in equal order. Hashing agrees with equality, so a set can be a lookup key.
§Storage form
The GVariant type is a(ayay). Each element is a pair of byte strings:
the name and the value. The pairs are sorted by name in byte order.
A stored name is the attribute name with its namespace prefix, followed by
one NUL byte. The text before the NUL is not empty and holds no NUL. The
ostree command writes names in this form.
The xattr bytes are part of the object checksum, so each constructor makes a canonical set. Each serialization and each hash of a set uses this form.
new sorts the pairs.
from_gvariant refuses pairs that are not
sorted. Each constructor refuses a duplicate name and checks each name.
Implementations§
Source§impl Xattrs
impl Xattrs
Sourcepub fn new(
pairs: impl IntoIterator<Item = (Vec<u8>, Vec<u8>)>,
) -> Result<Xattrs>
pub fn new( pairs: impl IntoIterator<Item = (Vec<u8>, Vec<u8>)>, ) -> Result<Xattrs>
Creates a canonical set from (name, value) pairs in any order.
The function sorts the pairs by name. Each name must be a stored name of the storage form, with one NUL byte at the end.
§Errors
Error::InvalidXattrs with one of these reasons:
duplicate xattr nameif two pairs have the same name.empty xattr nameif a name is empty.xattr name is missing its terminating NULif the last byte of a name is not NUL.xattr name is empty before its NULif a name is one NUL byte only.xattr name has an interior NULif a name holds a NUL byte before its last byte.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&[u8], &[u8])>
pub fn iter(&self) -> impl Iterator<Item = (&[u8], &[u8])>
Returns an iterator over the (name, value) entries, sorted by name.
Sourcepub fn to_gvariant(&self) -> Result<Vec<u8>>
pub fn to_gvariant(&self) -> Result<Vec<u8>>
Serializes the set as normal-form GVariant a(ayay).
§Errors
The function returns no error for any set. The encoder of a(ayay)
has no failure case.
Sourcepub fn from_gvariant(bytes: &[u8]) -> Result<Xattrs>
pub fn from_gvariant(bytes: &[u8]) -> Result<Xattrs>
Parses a normal-form GVariant a(ayay) set.
Each name must be greater than the name before it, in byte order. This check refuses unsorted input and duplicate names.
§Errors
Error::Gvariantifbytesis not a normal-forma(ayay)array.Error::InvalidXattrswith the reasonxattr names are not strictly sortedif a name is not greater than the name before it.Error::InvalidXattrsif a name is not in the stored form. The reasons areempty xattr name,xattr name is missing its terminating NUL,xattr name is empty before its NUL, andxattr name has an interior NUL, as fornew.
Trait Implementations§
impl Eq for Xattrs
Source§impl GvType for &Xattrs
The a(ayay) encoding of a set, written from the owned entries.
impl GvType for &Xattrs
The a(ayay) encoding of a set, written from the owned entries.
A dirmeta or a file header encodes its set as a member of a larger tuple with this impl. The encoder needs no list of borrowed pairs.