Skip to content

Commit f64e583

Browse files
joeyzhao2018claude
andcommitted
fix(msk): fix clippy lints in msk_event header parsing
- Replace `n as u8` cast with `u8::try_from(n).ok()` to avoid truncation - Collapse nested `if let` blocks into a single `if let ... && let ...` - Replace redundant closure `|o| o.len()` with `serde_json::Map::len` Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 9dbcb53 commit f64e583

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

bottlecap/src/lifecycle/invocation/triggers/msk_event.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn bytes_from_header_value(val: &Value) -> Option<Vec<u8>> {
3535
Value::Array(arr) => arr
3636
.iter()
3737
.map(|v| match v {
38-
Value::Number(n) => n.as_u64().map(|n| n as u8),
38+
Value::Number(n) => n.as_u64().and_then(|n| u8::try_from(n).ok()),
3939
Value::String(s) => s.parse::<u8>().ok(),
4040
_ => None,
4141
})
@@ -76,10 +76,10 @@ fn carrier_from_headers(headers: &Value) -> HashMap<String, String> {
7676
for entry in entries {
7777
if let Value::Object(header_map) = entry {
7878
for (key, val) in header_map {
79-
if let Some(bytes) = bytes_from_header_value(val) {
80-
if let Ok(s) = String::from_utf8(bytes) {
81-
carrier.insert(key.to_lowercase(), s);
82-
}
79+
if let Some(bytes) = bytes_from_header_value(val)
80+
&& let Ok(s) = String::from_utf8(bytes)
81+
{
82+
carrier.insert(key.to_lowercase(), s);
8383
}
8484
}
8585
}
@@ -430,7 +430,7 @@ mod tests {
430430
.expect("Expected at least one record");
431431
assert_eq!(record.topic, "demo-topic");
432432
// headers is an object with 6 entries (2 non-datadog + 4 datadog)
433-
assert_eq!(record.headers.as_object().map(|o| o.len()), Some(6));
433+
assert_eq!(record.headers.as_object().map(serde_json::Map::len), Some(6));
434434
}
435435

436436
#[test]

0 commit comments

Comments
 (0)