pax_runtime_api/pax_value/
macros.rs1#[macro_export]
3macro_rules! impl_default_coercion_rule {
4 ($Type:ty, $Variant:path) => {
5 impl CoercionRules for $Type {
6 fn try_coerce(pax_value: PaxValue) -> Result<Self, String> {
7 if let $Variant(val) = pax_value {
8 Ok(val.into())
9 } else {
10 Err(format!(
11 "couldn't coerce {:?} into {}",
12 pax_value,
13 std::any::type_name::<$Type>()
14 ))
15 }
16 }
17 }
18 };
19}
20
21#[macro_export]
23macro_rules! impl_to_from_pax_value {
24 ($Type:ty, $Variant:path) => {
26 impl ToPaxValue for $Type {
27 fn to_pax_value(self) -> PaxValue {
28 $Variant(self)
29 }
30 }
31 };
32 ($Type:ty, $OuterVariant:path, $InnerVariant:path) => {
35 impl ToPaxValue for $Type {
36 fn to_pax_value(self) -> PaxValue {
37 $OuterVariant($InnerVariant(self))
38 }
39 }
40 };
41}