How do I solve the error “the precise format of `Fn`-family traits' type parameters is subject to change”?

丶灬走出姿态 提交于 2019-12-01 06:42:16

The direct answer is to do exactly as the error message says:

Use parenthetical notation instead

That is, instead of Fn<(A, B)>, use Fn(A, B)

The real problem is that you are not allowed to implement the Fn* family of traits yourself in stable Rust.

The real question you are asking is harder to be sure of because you haven't provided a MCVE, so we are reduced to guessing. I'd say you should flip it around the other way; create a new trait, implement it for closures and your type:

trait Solve {
    type Output;
    fn solve(&mut self) -> Self::Output;
}

impl<F, T> Solve for F
where
    F: FnMut() -> T,
{
    type Output = T;

    fn solve(&mut self) -> Self::Output {
        (self)()
    }
}

struct Test;
impl Solve for Test {
    // interesting things
}

fn main() {}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!