From c7cf5ea44615b07eca8cca1cfe0440c90e9cdd80 Mon Sep 17 00:00:00 2001 From: Eguzki Astiz Lezaun Date: Thu, 12 Sep 2024 13:26:58 +0200 Subject: [PATCH] policy.rs: refactor unstable .inspect_err feature for rust <=1.75 Signed-off-by: Eguzki Astiz Lezaun --- src/policy.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/policy.rs b/src/policy.rs index 7b894c1..3473d38 100644 --- a/src/policy.rs +++ b/src/policy.rs @@ -140,10 +140,19 @@ impl Policy { } // TODO(eastizle): not all fields are strings // https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes - Some(attribute_bytes) => Attribute::parse(attribute_bytes) - .inspect_err(|e| debug!("#{} build_single_descriptor: failed to parse selector value: {}, error: {}", - filter.context_id, attribute_path, e)) - .ok()?, + Some(attribute_bytes) => match Attribute::parse(attribute_bytes) { + Ok(attr_str) => attr_str, + Err(e) => { + debug!("#{} build_single_descriptor: failed to parse selector value: {}, error: {}", + filter.context_id, attribute_path, e); + return None; + } + }, + // Alternative implementation (for rust >= 1.76) + // Attribute::parse(attribute_bytes) + // .inspect_err(|e| debug!("#{} build_single_descriptor: failed to parse selector value: {}, error: {}", + // filter.context_id, attribute_path, e)) + // .ok()?, }; let mut descriptor_entry = RateLimitDescriptor_Entry::new(); descriptor_entry.set_key(descriptor_key);