Repository: tokio-rs/mio (rust)

Issue:
UdpSocket::join_multicast_* APi does not match std lib's API
The std lib API accepts the addresses by reference, i.e. `&Ipv4Addr`, Mio however takes it by value `Ipv4Addr`. I think we should match the standard library API, although its inconsistent with `UdpSocket::bind`, which takes the address by value.

Pull request description:
Accept IPv4 multicast addresses by reference
This is not a breaking change, since the original PR to accept multicast addresses by value was only accepted in v7-alpha.

Furthermore, if this PR isn't merged, I suggest creating another PR that accepts ipv6 addresses by value, to maintain consistency with the ipv4 equivalents.

Fixes #1235 

Patch:
diff --git a/src/net/udp.rs b/src/net/udp.rs
index 46d288e..164315a 100644
--- a/src/net/udp.rs
+++ b/src/net/udp.rs
@@ -465,8 +465,9 @@ impl UdpSocket {
     /// address of the local interface with which the system should join the
     /// multicast group. If it's equal to `INADDR_ANY` then an appropriate
     /// interface is chosen by the system.
-    pub fn join_multicast_v4(&self, multiaddr: Ipv4Addr, interface: Ipv4Addr) -> io::Result<()> {
-        self.inner.join_multicast_v4(&multiaddr, &interface)
+    #[allow(clippy::trivially_copy_pass_by_ref)]
+    pub fn join_multicast_v4(&self, multiaddr: &Ipv4Addr, interface: &Ipv4Addr) -> io::Result<()> {
+        self.inner.join_multicast_v4(multiaddr, interface)
     }
 
     /// Executes an operation of the `IPV6_ADD_MEMBERSHIP` type.
@@ -474,6 +475,7 @@ impl UdpSocket {
     /// This function specifies a new multicast group for this socket to join.
     /// The address must be a valid multicast address, and `interface` is the
     /// index of the interface to join/leave (or 0 to indicate any interface).
+    #[allow(clippy::trivially_copy_pass_by_ref)]
     pub fn join_multicast_v6(&self, multiaddr: &Ipv6Addr, interface: u32) -> io::Result<()> {
         self.inner.join_multicast_v6(multiaddr, interface)
     }
@@ -484,8 +486,9 @@ impl UdpSocket {
     /// [`join_multicast_v4`][link].
     ///
     /// [link]: #method.join_multicast_v4
-    pub fn leave_multicast_v4(&self, multiaddr: Ipv4Addr, interface: Ipv4Addr) -> io::Result<()> {
-        self.inner.leave_multicast_v4(&multiaddr, &interface)
+    #[allow(clippy::trivially_copy_pass_by_ref)]
+    pub fn leave_multicast_v4(&self, multiaddr: &Ipv4Addr, interface: &Ipv4Addr) -> io::Result<()> {
+        self.inner.leave_multicast_v4(multiaddr, interface)
     }
 
     /// Executes an operation of the `IPV6_DROP_MEMBERSHIP` type.
@@ -494,6 +497,7 @@ impl UdpSocket {
     /// [`join_multicast_v6`][link].
     ///
     /// [link]: #method.join_multicast_v6
+    #[allow(clippy::trivially_copy_pass_by_ref)]
     pub fn leave_multicast_v6(&self, multiaddr: &Ipv6Addr, interface: u32) -> io::Result<()> {
         self.inner.leave_multicast_v6(multiaddr, interface)
     }


Test patch:
diff --git a/tests/udp_socket.rs b/tests/udp_socket.rs
index ec74c0b..874654d 100644
--- a/tests/udp_socket.rs
+++ b/tests/udp_socket.rs
@@ -933,12 +933,12 @@ pub fn multicast() {
     let mut rx = UdpSocket::bind(any_local_address()).unwrap();
 
     info!("Joining group 227.1.1.100");
-    let any = "0.0.0.0".parse().unwrap();
-    rx.join_multicast_v4("227.1.1.100".parse().unwrap(), any)
+    let any = &"0.0.0.0".parse().unwrap();
+    rx.join_multicast_v4(&"227.1.1.100".parse().unwrap(), any)
         .unwrap();
 
     info!("Joining group 227.1.1.101");
-    rx.join_multicast_v4("227.1.1.101".parse().unwrap(), any)
+    rx.join_multicast_v4(&"227.1.1.101".parse().unwrap(), any)
         .unwrap();
 
     info!("Registering SENDER");