#options #ing #deferring

some-mut

A utility library for deferring the take()ing of an Option

3 releases

0.1.2 Apr 14, 2023
0.1.1 Apr 14, 2023
0.1.0 Apr 14, 2023

#48 in #option

26 downloads per month

MIT license

7KB
80 lines

some-mut

A utility library that mainly lets you access a Some and then take() it infallibly.

Useful, for example, in a Future implementation, when you might re-enter into a function multiple times and so can't take() until a sub-future is Ready:

// for a theoretical `StreamExt::forward()`/`SinkExt::send_all()` implementation:
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Error>> {
    if let Some(buffered_item) = self.buffered_item.some_mut() {
        ready!(self.sink.poll_ready(cx))?;
        self.sink.start_send(buffered_item.take())?;
    }
    // ...
}

License

This project is licensed under the MIT license. Please see the LICENSE file for more details.


lib.rs:

A utility library that mainly lets you access a Some and then take() it infallibly.

Useful, for example, in a Future implementation, when you might re-enter into a function multiple times and so can't take() until a sub-future is Ready:

use some_mut::OptionExt;
// for a theoretical `StreamExt::forward()`/`SinkExt::send_all()` implementation:
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Error>> {
    let me = self.project();
    if let Some(buffered_item) = me.buffered_item.some_mut() {
        ready!(me.sink.poll_ready(cx))?;
        me.sink.start_send(buffered_item.take())?;
    }
    // ...
}

No runtime deps