diff --git a/coverage_config_x86_64.json b/coverage_config_x86_64.json index 8f24950..c3e6939 100644 --- a/coverage_config_x86_64.json +++ b/coverage_config_x86_64.json @@ -1 +1 @@ -{"coverage_score": 82.2, "exclude_path": "src/vhost_kern/", "crate_features": "vhost-user-master,vhost-user-slave"} +{"coverage_score": 82.3, "exclude_path": "src/vhost_kern/", "crate_features": "vhost-user-master,vhost-user-slave"} diff --git a/src/vhost_user/message.rs b/src/vhost_user/message.rs index f6eead2..fc33e1b 100644 --- a/src/vhost_user/message.rs +++ b/src/vhost_user/message.rs @@ -223,9 +223,8 @@ bitflags! { /// Common message header for vhost-user requests and replies. /// A vhost-user message consists of 3 header fields and an optional payload. All numbers are in the /// machine native byte order. -#[allow(safe_packed_borrows)] #[repr(packed)] -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Copy)] pub(super) struct VhostUserMsgHeader { request: u32, flags: u32, @@ -233,6 +232,28 @@ pub(super) struct VhostUserMsgHeader { _r: PhantomData, } +impl Debug for VhostUserMsgHeader { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Point") + .field("request", &{ self.request }) + .field("flags", &{ self.flags }) + .field("size", &{ self.size }) + .finish() + } +} + +impl Clone for VhostUserMsgHeader { + fn clone(&self) -> VhostUserMsgHeader { + *self + } +} + +impl PartialEq for VhostUserMsgHeader { + fn eq(&self, other: &Self) -> bool { + self.request == other.request && self.flags == other.flags && self.size == other.size + } +} + impl VhostUserMsgHeader { /// Create a new instance of `VhostUserMsgHeader`. pub fn new(request: R, flags: u32, size: u32) -> Self { @@ -249,7 +270,7 @@ impl VhostUserMsgHeader { /// Get message type. pub fn get_code(&self) -> R { // It's safe because R is marked as repr(u32). - unsafe { std::mem::transmute_copy::(&self.request) } + unsafe { std::mem::transmute_copy::(&{ self.request }) } } /// Set message type. @@ -803,7 +824,6 @@ impl DescStateSplit { } /// Inflight I/O queue region for split virtqueues -#[allow(safe_packed_borrows)] #[repr(packed)] pub struct QueueRegionSplit { /// Features flags of this region @@ -868,7 +888,6 @@ impl DescStatePacked { } /// Inflight I/O queue region for packed virtqueues -#[allow(safe_packed_borrows)] #[repr(packed)] pub struct QueueRegionPacked { /// Features flags of this region @@ -994,7 +1013,10 @@ mod tests { hdr.set_version(0x1); assert!(hdr.is_valid()); + // Test Debug, Clone, PartiaEq trait assert_eq!(hdr, hdr.clone()); + assert_eq!(hdr.clone().get_code(), hdr.get_code()); + assert_eq!(format!("{:?}", hdr.clone()), format!("{:?}", hdr)); } #[test]