Repository: actix/actix (language: rust)

Issue:
`SinkWrite::write` should return `Result<(), I>` instead of `Option<I>`
In version 0.9 and below [`SinkWrite::write`](https://docs.rs/actix/0.9.0/actix/io/struct.SinkWrite.html#method.write) would return a `Result`, but [in 0.10 it changed to return an `Option`](https://docs.rs/actix/0.10.0/actix/io/struct.SinkWrite.html#method.write) - I assume in order to return the unsent value?

Using `Option::None` as a success value is confusing - the idiomatic success value is `Ok`, and the idiomatic error value is `Err`. The fact that 0.10 had to document the meaning of the return value where in 0.9 it was obvious is a testimony to that. `Result<(), I>` is also returning the unsent item in case of failure, and is much less confusing.


Discussion / hints:
makes sense, PR welcome

Fix patch:
diff --git a/actix/CHANGES.md b/actix/CHANGES.md
index 08807f509..f46d2bbe2 100644
--- a/actix/CHANGES.md
+++ b/actix/CHANGES.md
@@ -8,10 +8,12 @@
 
 ### Changed
 - Make `Context::new` public. [#491]
+- `SinkWriter::write` returns `Result` instead of `Option`. [#499]
 
 [#419]: https://github.com/actix/actix/pull/419
 [#491]: https://github.com/actix/actix/pull/491
 [#493]: https://github.com/actix/actix/pull/493
+[#499]: https://github.com/actix/actix/pull/499
 
 
 ## 0.11.1 - 2021-03-23
diff --git a/actix/src/io.rs b/actix/src/io.rs
index 8827dd6f5..cc2cd6c30 100644
--- a/actix/src/io.rs
+++ b/actix/src/io.rs
@@ -442,13 +442,13 @@ impl<I: 'static, S: Sink<I> + Unpin + 'static> SinkWrite<I, S> {
     /// Queues an item to be sent to the sink.
     ///
     /// Returns unsent item if sink is closing or closed.
-    pub fn write(&mut self, item: I) -> Option<I> {
+    pub fn write(&mut self, item: I) -> Result<(), I> {
         if self.inner.borrow().closing_flag.is_empty() {
             self.inner.borrow_mut().buffer.push_back(item);
             self.notify_task();
-            None
+            Ok(())
         } else {
-            Some(item)
+            Err(item)
         }
     }
 


Test patch: