Macro netstack3_core::for_any_device_id

source ยท
macro_rules! for_any_device_id {
    ($device_id_enum_type:ident, $device_id:expr, $variable:pat => $expression:expr) => { ... };
    (
        $device_id_enum_type:ident,
        $provider_trait:ident,
        $type_param:ident,
        $device_id:expr, $variable:pat => $expression:expr) => { ... };
}
Expand description

Evaluates the expression for the given device_id, regardless of its variant.

This macro supports multiple forms.

Form #1: for_any_device_id!(device_id_enum, device_id, variable => expression)

  • device_id_enum: the type of device ID, either DeviceId or WeakDeviceId.
  • device_id: The id to match on. I.e. a value of type device_id_enum.
  • variable: The local variable to bind the inner device id type to. This variable may be referenced from expression.
  • expression: The expression to evaluate against the given device_id.

Example: for_any_device_id!(DeviceId, my_device, id => println!({:?}, id))

Form #2: for_any_device_id!(device_id_enum, provider_trait, type_param, device_id, variable => expression)

  • device_id_enum, device_id, variable, and expression: Same as for Form #1.
  • provider_trait: The DeviceProvider trait.
  • type_param: The name of the type parameter to hold the values provided by provider_trait. This type parameter may be referenced from expression.

The second form is useful in situations where the compiler cannot infer a device type that differs for each variant of device_id_enum.

Example: for_any_device_id!( DeviceId, DeviceProvider, D, my_device, id => fn_with_id::(id) )