Hi, on the std::convert::Into trait page, it says:
Library authors should not directly implement this trait, but should prefer implementing the From trait, which offers greater flexibility and provides an equivalent
Intoimplementation for free
The “greater flexibility” statement is hand-wavy to me (i.e. “believe me! it’s true” instead of “this is the rationale”).
In one of my projects, I’ve got:
- a varying number of custom record structs, e.g.
Since the custom record structs can keep growing, it seems to make sense that every time I add another
CustomXRecord struct, I should also
impl Into<StandardRecord> for CustomXRecord. But the advice above turns it around and says, actually you should
impl From<CustomXRecord> for StandardRecord.
So there’s two questions here:
- What’s the magic behind prefer
- Should I put the
impl From<CustomXRecord> for StandardRecordinside the
StandardRecords currently all live in the same crate.