ronantakizawa/codereview-bench huggingface dataset:
Repository: tokio-rs/tokio
File: tokio-util/tests/abort_on_drop.rs (Rust)

Code before:
    assert!(tx.is_closed());
}

#[tokio::test]
async fn handle_aborts_task_directly() {
    let (mut tx, rx) = oneshot::channel::<bool>();
    let handle = tokio::spawn(async move {
        let _ = rx.await;
    });
    let handle = AbortOnDrop::new(handle.abort_handle());
    handle.abort();
    tx.closed().await;
    assert!(tx.is_closed());
    assert!(handle.is_finished());
}

#[tokio::test]
async fn handle_does_not_abort_after_detach() {
    let (tx, rx) = oneshot::channel::<bool>();
    let handle = tokio::spawn(async move {
        let _ = rx.await;
    });
    let handle = AbortOnDrop::new(handle.abort_handle());
    handle.detach(); // returns and drops the original join handle
    yield_now().await;
    assert!(!tx.is_closed()); // task is still live
}


Review comment (suggestion):
```suggestion
    assert!(!tx.is_closed()); // the task is still alive
```

Code after:
    assert!(tx.is_closed());
}

#[tokio::test]
async fn handle_aborts_task_directly() {
    let (mut tx, rx) = oneshot::channel::<bool>();
    let handle = tokio::spawn(async move {
        let _ = rx.await;
    });
    let handle = AbortOnDrop::new(handle.abort_handle());
    handle.abort();
    tx.closed().await;
    assert!(tx.is_closed());
    assert!(handle.is_finished());
}

#[tokio::test]
async fn handle_does_not_abort_after_detach() {
    let (tx, rx) = oneshot::channel::<bool>();
    let handle = tokio::spawn(async move {
        let _ = rx.await;
    });
    let handle = AbortOnDrop::new(handle.abort_handle());
    handle.detach(); // returns and drops the original abort handle
    yield_now().await;
    assert!(!tx.is_closed()); // the task is still alive
}
Repository: tokio-rs/tokio
File: tokio-util/src/task/mod.rs (Rust)

Code before:
//! Extra utilities for spawning tasks
//!
//! This module is only available when the `rt` feature is enabled. Note that enabling the
//! `join-map` feature will automatically also enable the `rt` feature.

cfg_rt! {
    mod spawn_pinned;
    pub use spawn_pinned::LocalPoolHandle;

    pub mod task_tracker;
    #[doc(inline)]
    pub use task_tracker::TaskTracker;

    mod abort_on_drop;
    pub use abort_on_drop::{AbortOnDropHandle, AbortOnDrop};

    mod join_queue;
    pub use join_queue::JoinQueue;
}

#[cfg(feature = "join-map")]
mod join_map;
#[cfg(feature = "join-map")]
#[cfg_attr(docsrs, doc(cfg(feature = "join-map")))]
pub use join_map::{JoinMap, JoinMapKeys};


Review comment (suggestion):
```suggestion
    pub use abort_on_drop::{AbortOnDrop, AbortOnDropHandle};
```
nit: just to keep the imports order consistent with https://github.com/tokio-rs/tokio/pull/7855/changes#diff-25762358a8cae400f354bde1b017ea6e726ce1d62b07c1e288d9c278abbefc00R2 

Code after:
//! Extra utilities for spawning tasks
//!
//! This module is only available when the `rt` feature is enabled. Note that enabling the
//! `join-map` feature will automatically also enable the `rt` feature.

cfg_rt! {
    mod spawn_pinned;
    pub use spawn_pinned::LocalPoolHandle;

    pub mod task_tracker;
    #[doc(inline)]
    pub use task_tracker::TaskTracker;

    mod abort_on_drop;
    pub use abort_on_drop::{AbortOnDrop, AbortOnDropHandle};

    mod join_queue;
    pub use join_queue::JoinQueue;
}

#[cfg(feature = "join-map")]
mod join_map;
#[cfg(feature = "join-map")]
#[cfg_attr(docsrs, doc(cfg(feature = "join-map")))]
pub use join_map::{JoinMap, JoinMapKeys};
Repository: tokio-rs/tokio
File: tokio-util/src/task/abort_on_drop.rs (Rust)

Code before:
impl Drop for AbortOnDrop {
    fn drop(&mut self) {
        self.0.abort()
    }
}

impl AbortOnDrop {
    /// Create an [`AbortOnDrop`] from a [`AbortHandle`].
    pub fn new(handle: AbortHandle) -> Self {
        Self(handle)
    }

    /// Abort the task associated with this handle,
    /// equivalent to [`AbortHandle::abort`].
    pub fn abort(&self) {
        self.0.abort()
    }

    /// Checks if the task associated with this handle is finished,
    /// equivalent to [`AbortHandle::is_finished`].
    pub fn is_finished(&self) -> bool {
        self.0.is_finished()
    }

    /// Cancels aborting on drop and returns the original [`AbortHandle`].
    pub fn detach(self) -> AbortHandle {
        // Avoid invoking `AbortOnDrop`'s `Drop` impl
        let this = ManuallyDrop::new(self);
        // SAFETY: `&this.0` is a reference, so it is certainly initialized, and
        // it won't be double-dropped because it's in a `ManuallyDrop`
        unsafe { std::ptr::read(&this.0) }
    }
}

impl std::fmt::Debug for AbortOnDrop {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("AbortOnDrop")
            .field("id", &self.0.id())
            .finish()
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    /// A simple type that does not implement [`std::fmt::Debug`].
    struct NotDebug;

    fn is_debug<T: std::fmt::Debug>() {}


Review comment (suggestion):
```suggestion
    #[inline]
    pub fn is_finished(&self) -> bool {
```

Code after:
#[must_use = "Dropping the handle aborts the task immediately"]
pub struct AbortOnDrop(AbortHandle);

impl Drop for AbortOnDrop {
    fn drop(&mut self) {
        self.abort()
    }
}

impl AbortOnDrop {
    /// Create an [`AbortOnDrop`] from a [`AbortHandle`].
    pub fn new(handle: AbortHandle) -> Self {
        Self(handle)
    }

    /// Abort the task associated with this handle,
    /// equivalent to [`AbortHandle::abort`].
    #[inline]
    pub fn abort(&self) {
        self.0.abort()
    }

    /// Checks if the task associated with this handle is finished,
    /// equivalent to [`AbortHandle::is_finished`].
    #[inline]
    pub fn is_finished(&self) -> bool {
        self.0.is_finished()
    }

    /// Cancels aborting on drop and returns the original [`AbortHandle`].
    pub fn detach(self) -> AbortHandle {
        // Avoid invoking `AbortOnDrop`'s `Drop` impl
        let this = ManuallyDrop::new(self);
        // SAFETY: `&this.0` is a reference, so it is certainly initialized, and
        // it won't be double-dropped because it's in a `ManuallyDrop`
        unsafe { std::ptr::read(&this.0) }
    }
}

impl std::fmt::Debug for AbortOnDrop {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("AbortOnDrop")
            .field("id", &self.0.id())
            .finish()
    }
}

#[cfg(test)]
mod tests {
    use super::*;
Repository: tokio-rs/tokio
File: tokio-util/src/task/abort_on_drop.rs (Rust)

Code before:
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("AbortOnDropHandle")
            .field("id", &self.0.id())
            .finish()
    }
}

impl<T> Future for AbortOnDropHandle<T> {
    type Output = Result<T, JoinError>;

    fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
        Pin::new(&mut self.0).poll(cx)
    }
}

impl<T> AsRef<JoinHandle<T>> for AbortOnDropHandle<T> {
    fn as_ref(&self) -> &JoinHandle<T> {
        &self.0
    }
}

/// A wrapper around a [`tokio::task::AbortHandle`],
/// which [aborts] the task when it is dropped.
///
/// Unlike [`AbortOnDropHandle`], [`AbortOnDrop`] does not represent the permission to await a
/// tasks completion, and in exchange can be a concrete type.
///
///
/// [aborts]: tokio::task::JoinHandle::abort
#[must_use = "Dropping the handle aborts the task immediately"]
pub struct AbortOnDrop(AbortHandle);

impl Drop for AbortOnDrop {
    fn drop(&mut self) {
        self.0.abort()
    }
}

impl AbortOnDrop {
    /// Create an [`AbortOnDrop`] from a [`AbortHandle`].
    pub fn new(handle: AbortHandle) -> Self {
        Self(handle)
    }

    /// Abort the task associated with this handle,
    /// equivalent to [`AbortHandle::abort`].
    pub fn abort(&self) {
        self.0.abort()
    }

    /// Checks if the task associated with this handle is finished,

Review comment (suggestion):
```suggestion
/// task's completion, and in exchange can be a concrete type.
```

Code after:

impl<T> std::fmt::Debug for AbortOnDropHandle<T> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("AbortOnDropHandle")
            .field("id", &self.0.id())
            .finish()
    }
}

impl<T> Future for AbortOnDropHandle<T> {
    type Output = Result<T, JoinError>;

    fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
        Pin::new(&mut self.0).poll(cx)
    }
}

impl<T> AsRef<JoinHandle<T>> for AbortOnDropHandle<T> {
    fn as_ref(&self) -> &JoinHandle<T> {
        &self.0
    }
}

/// A wrapper around a [`tokio::task::AbortHandle`],
/// which [aborts] the task when it is dropped.
///
/// Unlike [`AbortOnDropHandle`], [`AbortOnDrop`] cannot be `.await`ed for a result.
///
/// It has no generic parameter, making it suitable when you only need to keep
/// a task handle in a struct and do not care about the output.
///
/// [aborts]: tokio::task::AbortHandle::abort
#[must_use = "Dropping the handle aborts the task immediately"]
pub struct AbortOnDrop(AbortHandle);

impl Drop for AbortOnDrop {
    fn drop(&mut self) {
        self.abort()
    }
}

impl AbortOnDrop {
    /// Create an [`AbortOnDrop`] from a [`AbortHandle`].
    pub fn new(handle: AbortHandle) -> Self {
        Self(handle)
    }

    /// Abort the task associated with this handle,
    /// equivalent to [`AbortHandle::abort`].
    #[inline]
    pub fn abort(&self) {
Repository: tokio-rs/tokio
File: tokio-util/src/task/abort_on_drop.rs (Rust)

Code before:
            .finish()
    }
}

impl<T> Future for AbortOnDropHandle<T> {
    type Output = Result<T, JoinError>;

    fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
        Pin::new(&mut self.0).poll(cx)
    }
}

impl<T> AsRef<JoinHandle<T>> for AbortOnDropHandle<T> {
    fn as_ref(&self) -> &JoinHandle<T> {
        &self.0
    }
}

/// A wrapper around a [`tokio::task::AbortHandle`],
/// which [aborts] the task when it is dropped.
///
/// Unlike [`AbortOnDropHandle`], [`AbortOnDrop`] does not represent the permission to await a
/// tasks completion, and in exchange can be a concrete type.
///
///
/// [aborts]: tokio::task::JoinHandle::abort
#[must_use = "Dropping the handle aborts the task immediately"]
pub struct AbortOnDrop(AbortHandle);

impl Drop for AbortOnDrop {
    fn drop(&mut self) {
        self.0.abort()
    }
}

impl AbortOnDrop {
    /// Create an [`AbortOnDrop`] from a [`AbortHandle`].
    pub fn new(handle: AbortHandle) -> Self {
        Self(handle)
    }

    /// Abort the task associated with this handle,
    /// equivalent to [`AbortHandle::abort`].
    pub fn abort(&self) {
        self.0.abort()
    }

    /// Checks if the task associated with this handle is finished,
    /// equivalent to [`AbortHandle::is_finished`].
    pub fn is_finished(&self) -> bool {
        self.0.is_finished()

Review comment (suggestion):
```suggestion
/// [aborts]: tokio::task::AbortHandle::abort
```

Code after:
        f.debug_struct("AbortOnDropHandle")
            .field("id", &self.0.id())
            .finish()
    }
}

impl<T> Future for AbortOnDropHandle<T> {
    type Output = Result<T, JoinError>;

    fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
        Pin::new(&mut self.0).poll(cx)
    }
}

impl<T> AsRef<JoinHandle<T>> for AbortOnDropHandle<T> {
    fn as_ref(&self) -> &JoinHandle<T> {
        &self.0
    }
}

/// A wrapper around a [`tokio::task::AbortHandle`],
/// which [aborts] the task when it is dropped.
///
/// Unlike [`AbortOnDropHandle`], [`AbortOnDrop`] cannot be `.await`ed for a result.
///
/// It has no generic parameter, making it suitable when you only need to keep
/// a task handle in a struct and do not care about the output.
///
/// [aborts]: tokio::task::AbortHandle::abort
#[must_use = "Dropping the handle aborts the task immediately"]
pub struct AbortOnDrop(AbortHandle);

impl Drop for AbortOnDrop {
    fn drop(&mut self) {
        self.abort()
    }
}

impl AbortOnDrop {
    /// Create an [`AbortOnDrop`] from a [`AbortHandle`].
    pub fn new(handle: AbortHandle) -> Self {
        Self(handle)
    }

    /// Abort the task associated with this handle,
    /// equivalent to [`AbortHandle::abort`].
    #[inline]
    pub fn abort(&self) {
        self.0.abort()
    }
Repository: tokio-rs/tokio
File: tokio-util/tests/abort_on_drop.rs (Rust)

Code before:
    drop(handle);
    tx.closed().await;
    assert!(tx.is_closed());
}

#[tokio::test]
async fn handle_aborts_task_directly() {
    let (mut tx, rx) = oneshot::channel::<bool>();
    let handle = tokio::spawn(async move {
        let _ = rx.await;
    });
    let handle = AbortOnDrop::new(handle.abort_handle());
    handle.abort();
    tx.closed().await;
    assert!(tx.is_closed());
    assert!(handle.is_finished());
}

#[tokio::test]
async fn handle_does_not_abort_after_detach() {
    let (tx, rx) = oneshot::channel::<bool>();
    let handle = tokio::spawn(async move {
        let _ = rx.await;
    });
    let handle = AbortOnDrop::new(handle.abort_handle());
    handle.detach(); // returns and drops the original join handle
    yield_now().await;
    assert!(!tx.is_closed()); // task is still live
}


Review comment (suggestion):
```suggestion
    handle.detach(); // returns and drops the original abort handle
```

Code after:
    drop(handle);
    tx.closed().await;
    assert!(tx.is_closed());
}

#[tokio::test]
async fn handle_aborts_task_directly() {
    let (mut tx, rx) = oneshot::channel::<bool>();
    let handle = tokio::spawn(async move {
        let _ = rx.await;
    });
    let handle = AbortOnDrop::new(handle.abort_handle());
    handle.abort();
    tx.closed().await;
    assert!(tx.is_closed());
    assert!(handle.is_finished());
}

#[tokio::test]
async fn handle_does_not_abort_after_detach() {
    let (tx, rx) = oneshot::channel::<bool>();
    let handle = tokio::spawn(async move {
        let _ = rx.await;
    });
    let handle = AbortOnDrop::new(handle.abort_handle());
    handle.detach(); // returns and drops the original abort handle
    yield_now().await;
    assert!(!tx.is_closed()); // the task is still alive
}
Repository: tokio-rs/tokio
File: tokio-util/src/io/simplex.rs (Rust)

Code before:

    fn close_receiver(&mut self) -> Option<Waker> {
        self.is_closed = true;
        self.take_sender_waker()
    }

    fn close_sender(&mut self) -> Option<Waker> {
        self.is_closed = true;
        self.take_receiver_waker()
    }
}

/// Receiver of the simplex channel.
///
/// # Cancellation safety
///
/// The `Receiver` is cancel safe. If it is used as the event in a
/// [`tokio::select!`] statement and some other branch completes
/// first, it is guaranteed that no bytes were received on this
/// channel.
///
/// You can still read the remaining data from the buffer
/// even if the write half has been dropped.
/// See [`Sender::poll_shutdown`] and [`Sender::drop`] for more details.
///
/// [`tokio::select!`]: https://docs.rs/tokio/1.0/tokio/macro.select.html
#[derive(Debug)]
pub struct Receiver {
    inner: Arc<Mutex<Inner>>,
}

impl Drop for Receiver {
    /// This also wakes up the [`Sender`].
    fn drop(&mut self) {
        let maybe_waker = {
            let mut inner = self.inner.lock().unwrap();
            inner.close_receiver()
        };

        if let Some(waker) = maybe_waker {
            waker.wake();
        }
    }
}

impl AsyncRead for Receiver {
    fn poll_read(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
        buf: &mut ReadBuf<'_>,
    ) -> Poll<IoResult<()>> {

Review comment (suggestion):
```suggestion
/// [`tokio::select!`]: https://docs.rs/tokio/latest/tokio/macro.select.html
```

Code after:

    fn close_receiver(&mut self) -> Option<Waker> {
        self.is_closed = true;
        self.take_sender_waker()
    }

    fn close_sender(&mut self) -> Option<Waker> {
        self.is_closed = true;
        self.take_receiver_waker()
    }
}

/// Receiver of the simplex channel.
///
/// # Cancellation safety
///
/// The `Receiver` is cancel safe. If it is used as the event in a
/// [`tokio::select!`] statement and some other branch completes
/// first, it is guaranteed that no bytes were received on this
/// channel.
///
/// You can still read the remaining data from the buffer
/// even if the write half has been dropped.
/// See [`Sender::poll_shutdown`] and [`Sender::drop`] for more details.
///
/// [`tokio::select!`]: https://docs.rs/tokio/latest/tokio/macro.select.html
#[derive(Debug)]
pub struct Receiver {
    inner: Arc<Mutex<Inner>>,
}

impl Drop for Receiver {
    /// This also wakes up the [`Sender`].
    fn drop(&mut self) {
        let maybe_waker = {
            let mut inner = self.inner.lock().unwrap();
            inner.close_receiver()
        };

        if let Some(waker) = maybe_waker {
            waker.wake();
        }
    }
}

impl AsyncRead for Receiver {
    fn poll_read(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
        buf: &mut ReadBuf<'_>,
    ) -> Poll<IoResult<()>> {
Repository: tokio-rs/tokio
File: tokio-util/src/io/simplex.rs (Rust)

Code before:
        buf.put_slice(&inner.buf[..to_read]);
        inner.buf.advance(to_read);

        let waker = inner.take_sender_waker();
        drop(inner); // unlock before waking up
        if let Some(waker) = waker {
            waker.wake();
        }

        Poll::Ready(Ok(()))
    }
}

/// Sender of the simplex channel.
///
/// # Cancellation safety
///
/// The `Sender` is cancel safe. If it is used as the event in a
/// [`tokio::select!`] statement and some other branch completes
/// first, it is guaranteed that no bytes were sent on this channel.
///
/// # Shutdown
///
/// See [`Sender::poll_shutdown`].
///
/// [`tokio::select!`]: https://docs.rs/tokio/1.0/tokio/macro.select.html
#[derive(Debug)]
pub struct Sender {
    inner: Arc<Mutex<Inner>>,
}

impl Drop for Sender {
    /// This also wakes up the [`Receiver`].
    fn drop(&mut self) {
        let maybe_waker = {
            let mut inner = self.inner.lock().unwrap();
            inner.close_sender()
        };

        if let Some(waker) = maybe_waker {
            waker.wake();
        }
    }
}

impl AsyncWrite for Sender {
    /// # Errors
    ///
    /// This method will return [`IoErrorKind::BrokenPipe`]
    /// if the channel has been closed.
    fn poll_write(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) -> Poll<IoResult<usize>> {

Review comment (suggestion):
```suggestion
/// [`tokio::select!`]: https://docs.rs/tokio/latest/tokio/macro.select.html
```

Code after:
        buf.put_slice(&inner.buf[..to_read]);
        inner.buf.advance(to_read);

        let waker = inner.take_sender_waker();
        drop(inner); // unlock before waking up
        if let Some(waker) = waker {
            waker.wake();
        }

        Poll::Ready(Ok(()))
    }
}

/// Sender of the simplex channel.
///
/// # Cancellation safety
///
/// The `Sender` is cancel safe. If it is used as the event in a
/// [`tokio::select!`] statement and some other branch completes
/// first, it is guaranteed that no bytes were sent on this channel.
///
/// # Shutdown
///
/// See [`Sender::poll_shutdown`].
///
/// [`tokio::select!`]: https://docs.rs/tokio/latest/tokio/macro.select.html
#[derive(Debug)]
pub struct Sender {
    inner: Arc<Mutex<Inner>>,
}

impl Drop for Sender {
    /// This also wakes up the [`Receiver`].
    fn drop(&mut self) {
        let maybe_waker = {
            let mut inner = self.inner.lock().unwrap();
            inner.close_sender()
        };

        if let Some(waker) = maybe_waker {
            waker.wake();
        }
    }
}

impl AsyncWrite for Sender {
    /// # Errors
    ///
    /// This method will return [`IoErrorKind::BrokenPipe`]
    /// if the channel has been closed.
    fn poll_write(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) -> Poll<IoResult<usize>> {
Repository: tokio-rs/tokio
File: tokio/tests/io_write_buf.rs (Rust)

Code before:

    impl AsyncWrite for Wr {
        fn poll_write(
            self: Pin<&mut Self>,
            _cx: &mut Context<'_>,
            _buf: &[u8],
        ) -> Poll<io::Result<usize>> {
            panic!("shouldn't be called")
        }

        fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> {
            Ok(()).into()
        }

        fn poll_shutdown(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> {
            Ok(()).into()
        }

        fn poll_write_vectored(
            mut self: Pin<&mut Self>,
            _cx: &mut Context<'_>,
            bufs: &[io::IoSlice<'_>],
        ) -> Poll<Result<usize, io::Error>> {
            let mut n = 0;
            for buf in bufs {
                let amt = cmp::min(4 - n, buf.len());
                self.buf.extend_from_slice(&buf[..amt]);
                n += amt;
                if n == 4 {
                    break;
                }
            }
            self.cnt += 1;
            Ok(n).into()
        }

        fn is_write_vectored(&self) -> bool {
            true
        }
    }

    let mut wr = Wr {
        buf: BytesMut::with_capacity(64),
        cnt: 0,
    };

    let mut buf = Cursor::new(&b"hello world"[..]);

    assert_ok!(wr.write_buf(&mut buf).await);
    assert_eq!(wr.buf, b"hell"[..]);
    assert_eq!(wr.cnt, 1);

Review comment (refactor):
nit: Maybe extract `4` as a local variable/constant, so it does not look like a magic number ?

Code after:

    impl AsyncWrite for Wr {
        fn poll_write(
            self: Pin<&mut Self>,
            _cx: &mut Context<'_>,
            _buf: &[u8],
        ) -> Poll<io::Result<usize>> {
            panic!("shouldn't be called")
        }

        fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> {
            Ok(()).into()
        }

        fn poll_shutdown(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> {
            Ok(()).into()
        }

        fn poll_write_vectored(
            mut self: Pin<&mut Self>,
            _cx: &mut Context<'_>,
            bufs: &[io::IoSlice<'_>],
        ) -> Poll<Result<usize, io::Error>> {
            let mut n = 0;
            for buf in bufs {
                self.buf.extend_from_slice(buf);
                n += buf.len();
            }
            self.cnt += 1;
            Ok(n).into()
        }

        fn is_write_vectored(&self) -> bool {
            true
        }
    }

    let mut wr = Wr {
        buf: BytesMut::with_capacity(64),
        cnt: 0,
    };

    let mut buf = Cursor::new(&b"hello world"[..]);

    assert_ok!(wr.write_buf(&mut buf).await);
    assert_eq!(wr.buf, b"hello world"[..]);
    assert_eq!(wr.cnt, 1);
    assert_eq!(buf.position(), 11);
}