[Feature Request] for `from`/`into`

Say we have struct X, struct Y, and struct Z, where X implements Into<Y> and Y implements Into<Z>. Then, X should implement Into<Z> automatically, with the filler code being similar to:

impl Into<Z> for X {
    fn into(self) -> Z {
        self.into::<Y>().into::<Z>()
    }
}

Unfortunately this isn't tenable. If you have many types Y to choose from, which one should you use for the transitive implementation?

10 Likes

There is a handy crate called transitive which allows you to derive transitive implementations of From, where you explicitly specify which conversions to go via. While not automatic, it at least means you don't need to write the filler code yourself.

2 Likes

A thing, similar to what @illicitonion mentioned, that I had published some time ago is this macro :slight_smile:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.