from_fn

Macro from_fn 

Source
macro_rules! from_fn {
    ($f:expr, $self:ident $(,$args:ident)*) => { ... };
    ($f:expr $(,$args:ident)*) => { ... };
}
Expand description

Creates a constructor for static functions.

It accepts as its parameters the target function followed by all the arguments required to invoke that function, returning a constructor for the return type of the function. The type of returned constructors can be obtained with Fn.

The provided function must be a static item which can be resolved at compile-time; therefore, closures are not supported. For methods, the second parameter must be self; otherwise, the returned constructor falls back to a bare function constructor.

ยงExample

async fn read_string(path: &str) -> String { String::new() }
let path = "/tmp/file";
let _: Fn!(_ => dyn Future<Output = String>) = from_fn!(read_string, path);