Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

One of the difficulties of breaking up a large crate is the Orphan Rule. I got bitten by it once. I had some traits and when I broke up the crate suddenly some types but also the traits were in different crates each.

I wanted to separate the type, the trait and the implementation of the trait in different crates. I was forced to use newtypes but newtypes need a lot of boiler plate. It was painful.

In my opinion this is a larger barrier than having separate Cargo.toml files.



> I wanted to separate the type, the trait and the implementation of the trait in different crates.

I usually put the traits in a separate crate, but keep concrete types and implementations for them in the same crate.

What is the use-case for splitting a type and it's implementation into separate crates? (except for cases where the trait or the type are out of your control, then one indeed needs to use the new-type escape hatch)


I had three different goals, one for the traits, one for something else where the types fit best, and the third which I achieved with the implementations of the traits.

The problem was that the trait implementations of the types was something like not a core task of the types themselves.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: