From 54e0e1ba113d09d07120b7be75e8432f9dfc7c80 Mon Sep 17 00:00:00 2001 From: Adam Gausmann Date: Thu, 8 Jul 2021 12:52:35 -0500 Subject: [PATCH] Differentiate between null and empty custom component data --- src/lib.rs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d4a8f7c..1fc462b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -92,17 +92,9 @@ struct Component { #[declio(ctx = "Len(outputs_len.0.try_into()?)")] outputs: Vec, custom_data_len: Int, - #[declio(ctx = "Len(len_or_neg1(*custom_data_len)?)")] - custom_data: Vec, -} - -fn len_or_neg1(len: Int) -> Result { - // From the spec: - // > If the component has no custom data, -1 may be written instead of 0 - match len.0 { - -1 => Ok(0), - other => other.try_into(), - } + #[declio(skip_if = "custom_data_len.0 == -1")] + #[declio(ctx = "Len(custom_data_len.0.try_into()?)")] + custom_data: Option>, } #[derive(Debug, Encode, Decode)]