Trait Attribute

Source
pub trait Attribute<T> {
    // Required methods
    fn payload(&self) -> &Buffer;
    fn set_payload<P>(&mut self, payload: &P) -> Result<(), SerError>
       where P: Size + ToBytes;

    // Provided methods
    fn get_payload_as<'a, R>(&'a self) -> Result<R, DeError>
       where R: FromBytes<'a> { ... }
    fn get_payload_as_with_len<'a, R>(&'a self) -> Result<R, DeError>
       where R: FromBytesWithInput<'a, Input = usize> { ... }
}
Expand description

Trait that defines shared operations for netlink attributes. Currently, this applies to generic netlink and routing netlink attributes.

Required Methods§

Source

fn payload(&self) -> &Buffer

Get the payload of the given attribute.

Due to Rust’s requirement that all elements of a Vec are of the same type, payloads are represented as a byte buffer so that nested attributes that contain multiple types for the payload can be type checked before serialization yet still contained all in the same top level attribute.

Source

fn set_payload<P>(&mut self, payload: &P) -> Result<(), SerError>
where P: Size + ToBytes,

Set the payload to a data type that implements ToBytes - this function will overwrite the current payload.

This method serializes the payload parameter and stores the resulting byte buffer as the payload.

Provided Methods§

Source

fn get_payload_as<'a, R>(&'a self) -> Result<R, DeError>
where R: FromBytes<'a>,

Get an Nlattr payload as the provided type parameter, R.

Source

fn get_payload_as_with_len<'a, R>(&'a self) -> Result<R, DeError>
where R: FromBytesWithInput<'a, Input = usize>,

Get an Nlattr payload as the provided type parameter, R.

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§

Source§

impl<T> Attribute<T> for Nlattr<T, Buffer>
where T: NlAttrType,

Source§

impl<T> Attribute<T> for Rtattr<T, Buffer>
where T: RtaType,