Trait AttributeOperations

Source
pub trait AttributeOperations<const ID: u64 = 0> {
    type Data;

    const USE_VTABLE_ATTR: ();
    const HAS_SHOW: bool = false;
    const HAS_STORE: bool = false;

    // Required method
    fn show(data: &Self::Data, page: &mut [u8; 4096]) -> Result<usize>;

    // Provided method
    fn store(_data: &Self::Data, _page: &[u8]) -> Result { ... }
}
Expand description

Operations supported by an attribute.

Implement this trait on type and pass that type as generic parameter when creating an Attribute. The type carrying the implementation serve no purpose other than specifying the attribute operations.

This trait must be implemented on the Data type of for types that implement HasGroup<Data>. The trait must be implemented once for each attribute of the group. The constant type parameter ID maps the implementation to a specific Attribute. ID must be passed when declaring attributes via the kernel::configfs_attrs macro, to tie AttributeOperations implementations to concrete named attributes.

Required Associated Constants§

Source

const USE_VTABLE_ATTR: ()

A marker to prevent implementors from forgetting to use #[vtable] attribute when implementing this trait.

Provided Associated Constants§

Source

const HAS_SHOW: bool = false

Indicates if the show method is overridden by the implementor.

Source

const HAS_STORE: bool = false

Indicates if the store method is overridden by the implementor.

Required Associated Types§

Source

type Data

The type of the object that contains the field that is backing the attribute for this operation.

Required Methods§

Source

fn show(data: &Self::Data, page: &mut [u8; 4096]) -> Result<usize>

Renders the value of an attribute.

This function is called by the kernel to read the value of an attribute.

Implementations should write the rendering of the attribute to page and return the number of bytes written.

Provided Methods§

Source

fn store(_data: &Self::Data, _page: &[u8]) -> Result

Stores the value of an attribute.

This function is called by the kernel to update the value of an attribute.

Implementations should parse the value from page and update internal state to reflect the parsed value.

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.

Implementors§