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, eitherDeviceId
orWeakDeviceId
.device_id
: The id to match on. I.e. a value of typedevice_id_enum
.variable
: The local variable to bind the inner device id type to. This variable may be referenced fromexpression
.expression
: The expression to evaluate against the givendevice_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
, andexpression
: Same as for Form #1.provider_trait
: TheDeviceProvider
trait.type_param
: The name of the type parameter to hold the values provided byprovider_trait
. This type parameter may be referenced fromexpression
.
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::