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 <cppcoffee@gmail.com>
reviewable/pr1304/r1
Xiaobo Liu 6 days ago
parent f635d80708
commit 2ef8bd163d

@ -96,9 +96,6 @@ impl<K> SockHash<K> {
let sk = lookup(self.def.get(), key.borrow()).ok_or(1u32)?; 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) }; let ret = unsafe { bpf_sk_assign(ctx.as_ptr().cast(), sk.as_ptr(), flags) };
unsafe { bpf_sk_release(sk.as_ptr()) }; unsafe { bpf_sk_release(sk.as_ptr()) };
match ret { (ret == 0).then_some(()).ok_or(1)
0 => Ok(()),
_ret => Err(1),
}
} }
} }

Loading…
Cancel
Save