The alternative way of creating a struct, and think about whether some field is structurally pinned, feels too heavy for an ad-hoc future only used in one place. I imagine poll_fn
is used because of that reason.
With RFC 2781, one can easily write an ad-hoc future without any unsafe
, like:
let future = fut();
let f: impl FnPin(&mut Context) -> Poll<()> = move |ctx| {
pin_mut!(future);
loop {
yield future.poll(ctx);
}
};
let f: impl Future = poll_fn_pin(f);