Function tsukuyomi::input::with_get_current[][src]

pub fn with_get_current<R>(
    f: impl FnOnce(&mut Input) -> R
) -> R

Acquires a mutable borrow of Input from the current task context and executes the provided closure with its reference.

Panics

This function only work in the management of the framework and causes a panic if any references to Input is not set at the current task. Do not use this function outside of futures returned by the handler functions. Such situations often occurs by spawning tasks by the external Executor (typically calling tokio::spawn()).

In additional, this function forms a (dynamic) scope to prevent the references to Input violate the borrowing rule in Rust. Duplicate borrowings such as the following code are reported as a runtime error.

This example is not tested
with_get_current(|input| {
    some_process()
});

fn some_process() {
    // Duplicate borrowing of `Input` occurs at this point.
    with_get_current(|input| { ... })
}