Derive Macro roboplc::DataPolicy

source ·
#[derive(DataPolicy)]
{
    // Attributes available to this derive:
    #[data_delivery]
    #[data_priority]
    #[data_expires]
}
Expand description

Automatically implements the DataDeliveryPolicy trait for an enum

Atrributes (should be spcified for each enum variant):

  • data_delivery - Specifies the delivery policy for a variant. The value can be one of the following: single, single_optional, optional, always. If not specified, the default is always.

  • data_priority - Specifies the priority for a variant, lower is better. The value must be an integer. If not specified, the default is 100.

  • data_expires - Specifies if the data expires. The value must be a function that returns boolean. If not specified, the default is false (i.e. data does not expire). For named associated data, the source MUST be stored in value field.

Example:

use roboplc::DataPolicy;
use roboplc::ttlcell::TtlCell;

#[derive(DataPolicy)]
enum MyEnum {
   #[data_delivery(single)]
   #[data_priority(10)]
   #[data_expires(TtlCell::is_expired)]
   SensorData(TtlCell<f32>),
   #[data_delivery(optional)]
   DatabaseTelemetry(f32),
   // the default one, can be omitted
   #[data_delivery(always)]
   Shutdown,
}

§Panics

Will panic on parse errors