Crate some_mut

Source
Expand description

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())?;
    }
    // ...
}

Structs§

SomeMut
A mutable reference to an Option that is guaranteed to always be Some.

Traits§

OptionExt
An extension trait that allows one to obtain a SomeMut.