Skip to main content

Xattrs

Struct Xattrs 

Source
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

Source

pub fn empty() -> Xattrs

Creates an empty set.

Source

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 name if two pairs have the same name.
  • empty xattr name if a name is empty.
  • xattr name is missing its terminating NUL if the last byte of a name is not NUL.
  • xattr name is empty before its NUL if a name is one NUL byte only.
  • xattr name has an interior NUL if a name holds a NUL byte before its last byte.
Source

pub fn is_empty(&self) -> bool

Returns true if the set has no entries.

Source

pub fn len(&self) -> usize

Returns the number of entries.

Source

pub fn iter(&self) -> impl Iterator<Item = (&[u8], &[u8])>

Returns an iterator over the (name, value) entries, sorted by name.

Source

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.

Source

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::Gvariant if bytes is not a normal-form a(ayay) array.
  • Error::InvalidXattrs with the reason xattr names are not strictly sorted if a name is not greater than the name before it.
  • Error::InvalidXattrs if a name is not in the stored form. The reasons are empty xattr name, xattr name is missing its terminating NUL, xattr name is empty before its NUL, and xattr name has an interior NUL, as for new.

Trait Implementations§

Source§

impl Clone for Xattrs

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Xattrs

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Xattrs

Source§

fn default() -> Self

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

impl Eq for Xattrs

Source§

impl GvEncode for &Xattrs

Source§

fn encode(&self, out: &mut Vec<u8>) -> Result<()>

Appends the normal-form bytes of self to out. Read more
Source§

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.

Source§

const SIGNATURE: &'static str = "a(ayay)"

The GVariant type signature, or "" for a container type. Read more
Source§

const ALIGNMENT: usize = 1

The alignment of the serialized form, in bytes.
Source§

const FIXED_SIZE: Option<usize> = None

The serialized size, or None for a variable-size type.
Source§

impl Hash for Xattrs

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Xattrs

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Xattrs

Auto Trait Implementations§

§

impl Forget for Xattrs

§

impl Freeze for Xattrs
where *const u8 is !null: Freeze, PhantomData<(Vec<u8>, Vec<u8>)>: Freeze,

§

impl Move for Xattrs

§

impl RefUnwindSafe for Xattrs

§

impl Send for Xattrs
where RawVecInner: Send,

§

impl Sync for Xattrs
where RawVecInner: Sync,

§

impl Unpin for Xattrs
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for Xattrs

§

impl UnwindSafe for Xattrs
where RawVecInner: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.