Skip to content

Commit

Permalink
policy.rs: refactor unstable .inspect_err feature for rust <=1.75
Browse files Browse the repository at this point in the history
Signed-off-by: Eguzki Astiz Lezaun <eastizle@redhat.com>
  • Loading branch information
eguzki committed Sep 12, 2024
1 parent ff7e501 commit c7cf5ea
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c7cf5ea

Please sign in to comment.