diff options
author | Chirantan Ekbote <chirantan@chromium.org> | 2020-01-16 16:49:14 +0900 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-01-17 13:17:39 +0000 |
commit | 5058253c98273a98257ba090ceed9720aae3599c (patch) | |
tree | f6326b7f94e11cfff284f8e253c732806b59c081 /src/linux.rs | |
parent | 470b1e7508005ae875c3e4a42fc22fb176f263ba (diff) | |
download | crosvm-5058253c98273a98257ba090ceed9720aae3599c.tar crosvm-5058253c98273a98257ba090ceed9720aae3599c.tar.gz crosvm-5058253c98273a98257ba090ceed9720aae3599c.tar.bz2 crosvm-5058253c98273a98257ba090ceed9720aae3599c.tar.lz crosvm-5058253c98273a98257ba090ceed9720aae3599c.tar.xz crosvm-5058253c98273a98257ba090ceed9720aae3599c.tar.zst crosvm-5058253c98273a98257ba090ceed9720aae3599c.zip |
MsgSocket: Don't implement Deref
The Deref trait is usually only implemented by smart pointers or by trivial wrappers around the underlying type. MsgSocket does not fit into either category because it wraps a `UnixSeqPacket` to provide new functionality. Having it implement can lead to confusing error messages, especially for people who are new to rust and are not familiar with the Deref trait and Deref coercion. For example, calling `sock.send()` on a MsgSocket without first adding `use msg_socket::MsgSender` leads to the compiler complaining about mis-matched types for the `send` method. `UnixSeqPacket::send` expects a `&[u8]` while `MsgSocket::send` expects a `&M`. The compiler also gives no clues that it is implicitly coercing the socket to a `&UnixSeqPacket` and using the `send` method from there. Drop the `Deref` implementation. `MsgSocket` already implements `AsRef<UniqSeqPacket>` so anything that _needs_ to access the underlying `UnixSeqPacket` should just use that. BUG=none TEST=unit tests Change-Id: If02ef7173ae21d85d517e808489ed4d6d09ae90b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2002997 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Diffstat (limited to 'src/linux.rs')
-rw-r--r-- | src/linux.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/linux.rs b/src/linux.rs index d6b6519..0637fa5 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -274,9 +274,9 @@ impl AsRef<UnixSeqpacket> for TaggedControlSocket { fn as_ref(&self) -> &UnixSeqpacket { use self::TaggedControlSocket::*; match &self { - Vm(ref socket) => socket, - VmMemory(ref socket) => socket, - VmIrq(ref socket) => socket, + Vm(ref socket) => socket.as_ref(), + VmMemory(ref socket) => socket.as_ref(), + VmIrq(ref socket) => socket.as_ref(), } } } |