From 2ef8bd163d0f0ec3a35614a70e4d2071427d55bd Mon Sep 17 00:00:00 2001 From: Xiaobo Liu Date: Sun, 20 Jul 2025 21:31:47 +0800 Subject: [PATCH] aya-ebpf: replace match statement with then_some for cleaner code Replace verbose match statement with more idiomatic then_some().ok_or() pattern for handling boolean return values in assign method. Signed-off-by: Xiaobo Liu --- ebpf/aya-ebpf/src/maps/sock_hash.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/ebpf/aya-ebpf/src/maps/sock_hash.rs b/ebpf/aya-ebpf/src/maps/sock_hash.rs index fe7fc25b..0fe02375 100644 --- a/ebpf/aya-ebpf/src/maps/sock_hash.rs +++ b/ebpf/aya-ebpf/src/maps/sock_hash.rs @@ -96,9 +96,6 @@ impl SockHash { let sk = lookup(self.def.get(), key.borrow()).ok_or(1u32)?; let ret = unsafe { bpf_sk_assign(ctx.as_ptr().cast(), sk.as_ptr(), flags) }; unsafe { bpf_sk_release(sk.as_ptr()) }; - match ret { - 0 => Ok(()), - _ret => Err(1), - } + (ret == 0).then_some(()).ok_or(1) } }