Repository: alexcrichton/futures-rs (rust)

Issue:
Ergonomics of channel send
Consider this code:

```rust
use futures::*;

fn main() {
    let (mut tx, rx) = futures::sync::mpsc::unbounded();
    tx.send(1);
}
```
You might think this is actually sending the message on the channel, but it's not because `Sink` has been imported via the glob import (and I'd imagine most users are using the glob import) so it's calling `Sink::send` not `UnboundedSender::send` (since `UnboundedSender` impls `Sink`).

We'd have to use UFCS instead:

```rust
fn main() {
    let (mut tx, rx) = futures::sync::mpsc::unbounded();
    UnboundedSender::send(&mut tx, 1).unwrap();
}
```

I guess the compiler warnings will lead the user to fix the code, but figured I would at least document it here.

Pull request description:
Rename `UnboundedSender::send` to `send_now`
This method conflicts with `Sink::send` which is unlikely to be renamed, so this
commit renames the method on `UnboundedSender`.

Closes #261

Patch:
diff --git a/src/sync/mpsc/mod.rs b/src/sync/mpsc/mod.rs
index a901d0ad..d8bd825d 100644
--- a/src/sync/mpsc/mod.rs
+++ b/src/sync/mpsc/mod.rs
@@ -518,7 +518,18 @@ impl<T> UnboundedSender<T> {
     /// This is an unbounded sender, so this function differs from `Sink::send`
     /// by ensuring the return type reflects that the channel is always ready to
     /// receive messages.
+    #[deprecated(note = "renamed to `unbounded_send`")]
+    #[doc(hidden)]
     pub fn send(&self, msg: T) -> Result<(), SendError<T>> {
+        self.unbounded_send(msg)
+    }
+
+    /// Sends the provided message along this channel.
+    ///
+    /// This is an unbounded sender, so this function differs from `Sink::send`
+    /// by ensuring the return type reflects that the channel is always ready to
+    /// receive messages.
+    pub fn unbounded_send(&self, msg: T) -> Result<(), SendError<T>> {
         self.0.do_send_nb(msg)
     }
 }
diff --git a/src/unsync/mpsc.rs b/src/unsync/mpsc.rs
index b7d7982e..c0974072 100644
--- a/src/unsync/mpsc.rs
+++ b/src/unsync/mpsc.rs
@@ -255,7 +255,18 @@ impl<T> UnboundedSender<T> {
     /// This is an unbounded sender, so this function differs from `Sink::send`
     /// by ensuring the return type reflects that the channel is always ready to
     /// receive messages.
+    #[deprecated(note = "renamed to `unbounded_send`")]
+    #[doc(hidden)]
     pub fn send(&self, msg: T) -> Result<(), SendError<T>> {
+        self.unbounded_send(msg)
+    }
+
+    /// Sends the provided message along this channel.
+    ///
+    /// This is an unbounded sender, so this function differs from `Sink::send`
+    /// by ensuring the return type reflects that the channel is always ready to
+    /// receive messages.
+    pub fn unbounded_send(&self, msg: T) -> Result<(), SendError<T>> {
         let shared = match self.0.shared.upgrade() {
             Some(shared) => shared,
             None => return Err(SendError(msg)),


Test patch:
diff --git a/tests/mpsc.rs b/tests/mpsc.rs
index a4e114dc..065974d7 100644
--- a/tests/mpsc.rs
+++ b/tests/mpsc.rs
@@ -165,7 +165,7 @@ fn stress_shared_unbounded() {
 
         thread::spawn(move|| {
             for _ in 0..AMT {
-                mpsc::UnboundedSender::send(&tx, 1).unwrap();
+                tx.unbounded_send(1).unwrap();
             }
         });
     }
@@ -314,7 +314,7 @@ fn stress_close_receiver_iter() {
     let (unwritten_tx, unwritten_rx) = std::sync::mpsc::channel();
     thread::spawn(move || {
         for i in 1.. {
-            if let Err(_) = mpsc::UnboundedSender::send(&tx, i) {
+            if let Err(_) = tx.unbounded_send(i) {
                 unwritten_tx.send(i).expect("unwritten_tx");
                 return;
             }
diff --git a/tests/shared.rs b/tests/shared.rs
index c296d597..0516177d 100644
--- a/tests/shared.rs
+++ b/tests/shared.rs
@@ -155,7 +155,7 @@ fn recursive_poll() {
     let f1 = run_stream.shared();
     let f2 = f1.clone();
     let f3 = f1.clone();
-    tx0.send(Box::new(
+    tx0.unbounded_send(Box::new(
         f1.map(|_|()).map_err(|_|())
             .select(rx1.map_err(|_|()))
             .map(|_| ()).map_err(|_|()))).unwrap();
@@ -185,7 +185,7 @@ fn recursive_poll_with_unpark() {
     let f1 = run_stream.shared();
     let f2 = f1.clone();
     let f3 = f1.clone();
-    tx0.send(Box::new(future::lazy(move || {
+    tx0.unbounded_send(Box::new(future::lazy(move || {
         task::current().notify();
         f1.map(|_|()).map_err(|_|())
             .select(rx1.map_err(|_|()))