pub fn init_scope<T, E, F, I>(make_init: F) -> impl Init<T, E>Expand description
Construct an initializer in a closure and run it.
Returns an initializer that first runs the closure and then the initializer returned by it.
See also pin_init_scope.
ยงExamples
fn init_foo() -> impl Init<Foo, Error> {
init_scope(|| {
let bar = lookup_bar()?;
Ok(try_init!(Foo { a: bar.a.into(), b: bar.b }? Error))
})
}This initializer will first execute lookup_bar(), match on it, if it returned an error, the
initializer itself will fail with that error. If it returned Ok, then it will run the
initializer returned by the try_init! invocation.