Trait AttributeExt

Source
pub trait AttributeExt {
    // Required methods
    fn iter_attributes(&self) -> Result<AttributeIterator>;
    fn find_attribute(&self, name: &str) -> Result<AttributeDescriptor>;
    fn read_attribute_raw(
        &self,
        name: &str,
        raw_type: type_code,
        pos: off_t,
        size: i64,
    ) -> Result<Vec<u8>>;
    fn write_attribute_raw(
        &self,
        name: &str,
        raw_type: type_code,
        pos: off_t,
        buffer: &[u8],
    ) -> Result<()>;
    fn remove_attribute(&self, name: &str) -> Result<()>;

    // Provided methods
    fn read_attribute<T: Flattenable<T>>(
        &self,
        attribute: &AttributeDescriptor,
    ) -> Result<T> { ... }
    fn write_attribute<T: Flattenable<T>>(
        &self,
        name: &str,
        value: &T,
    ) -> Result<()> { ... }
}
Expand description

The AttributeExt trait allows for reading attributes on file system objects

Implementors of this attribute allow you to read file (and directory) attributes that are implemented for Haiku’s native BFS. The trait is implemented for both File and Path objects.

Required Methods§

Source

fn iter_attributes(&self) -> Result<AttributeIterator>

The attribute iterator returns an iterator over all the attributes.

Source

fn find_attribute(&self, name: &str) -> Result<AttributeDescriptor>

Find an attribute by name

If the attribute cannot be found, an error will be returned.

Source

fn read_attribute_raw( &self, name: &str, raw_type: type_code, pos: off_t, size: i64, ) -> Result<Vec<u8>>

Read an attribute as a vector of bytes

This method is the low level implementation of the read_attribute method, that is available to read the contents of an attribute into any type that implements the Flattenable interface. It is advised to use the higher level implementation if you know which Rust type you want to use.

Note that when you implement this trait for your object, that it is valid to call this method with size 0. If that’s the case, the caller expects to get the whole attribute, possibly offset by pos.

Source

fn write_attribute_raw( &self, name: &str, raw_type: type_code, pos: off_t, buffer: &[u8], ) -> Result<()>

Write an attribute from a slice of bytes

This method is the low level implementation of the write_attribute method, that is available to write any type that implements the Flattenable interface as a file system attribute.

Note that this method does not do any check if the data you are writing is valid for the type you are trying to store. Therefore it is advisable to use the higher level write_attribute method.

Source

fn remove_attribute(&self, name: &str) -> Result<()>

Remove the attribute with the given name

Provided Methods§

Source

fn read_attribute<T: Flattenable<T>>( &self, attribute: &AttributeDescriptor, ) -> Result<T>

Read an attribute and return a Rust object

This method reads the attribute and returns it in the type T. Please note that you should make sure that the type T matches the type in the AttributeDescriptor. The type T should implement the Flattenable trait.

Source

fn write_attribute<T: Flattenable<T>>( &self, name: &str, value: &T, ) -> Result<()>

Write an object as a file system attribute

This method writes a copy of any object that implements the Flattenable trait to the file system.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl AttributeExt for File

Source§

fn iter_attributes(&self) -> Result<AttributeIterator>

Source§

fn find_attribute(&self, name: &str) -> Result<AttributeDescriptor>

Source§

fn read_attribute_raw( &self, name: &str, _raw_type: u32, pos: off_t, size: i64, ) -> Result<Vec<u8>>

Source§

fn write_attribute_raw( &self, name: &str, raw_type: u32, pos: off_t, buffer: &[u8], ) -> Result<()>

Source§

fn remove_attribute(&self, name: &str) -> Result<()>

Source§

impl AttributeExt for Path

Source§

fn iter_attributes(&self) -> Result<AttributeIterator>

Source§

fn find_attribute(&self, name: &str) -> Result<AttributeDescriptor>

Source§

fn read_attribute_raw( &self, name: &str, raw_type: u32, pos: off_t, size: i64, ) -> Result<Vec<u8>>

Source§

fn write_attribute_raw( &self, name: &str, raw_type: u32, pos: off_t, buffer: &[u8], ) -> Result<()>

Source§

fn remove_attribute(&self, name: &str) -> Result<()>

Implementors§