From 096ffe08f244fa0d35bc44a3987a671ffe5b83a4 Mon Sep 17 00:00:00 2001 From: Stefano Garzarella Date: Mon, 15 Jun 2020 18:41:32 +0200 Subject: [PATCH] vm-virtio: vsock: add `is_empty` method to VsockPacket This patch adds `is_empty` method to VsockPacket to fix the following clippy error: error: item `vsock::packet::VsockPacket` has a public `len` method but no corresponding `is_empty` method --> vm-virtio/src/vsock/packet.rs:100:1 | 100 | / impl VsockPacket { 101 | | /// Create the packet wrapper from a TX virtq chain head. 102 | | /// 103 | | /// The chain head is expected to hold valid packet header data. A following packet buffer ... | 334 | | } 335 | | } | |_^ | = note: `-D clippy::len-without-is-empty` implied by `-D warnings` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_without_is_empty Signed-off-by: Stefano Garzarella --- vm-virtio/src/vsock/packet.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vm-virtio/src/vsock/packet.rs b/vm-virtio/src/vsock/packet.rs index 168f382bf..fa5e9f8ae 100644 --- a/vm-virtio/src/vsock/packet.rs +++ b/vm-virtio/src/vsock/packet.rs @@ -124,7 +124,7 @@ impl VsockPacket { }; // No point looking for a data/buffer descriptor, if the packet is zero-lengthed. - if pkt.len() == 0 { + if pkt.is_empty() { return Ok(pkt); } @@ -278,6 +278,10 @@ impl VsockPacket { LittleEndian::read_u32(&self.hdr()[HDROFF_LEN..]) } + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + pub fn set_len(&mut self, len: u32) -> &mut Self { LittleEndian::write_u32(&mut self.hdr_mut()[HDROFF_LEN..], len); self