Elektrine lite

← Feed

@lholten@hachyderm.io

Post #436049

2026-02-20 16:00 UTC

I am currently cleaning up a messy codebase and I need your Rust style opinions! In those situations where both options are viable, you prefer placing trait implementations

Replies (3)

  • @lholten@hachyderm.io 2026-02-20 20:04

    This is funny, I think it is almost always better to put trait implementations together with the trait definition when possible. It is more consistent with the trait implementations for external types and as a bonus it makes it easier to reuse code between the implementations.

    Open ##2762567

  • @lilyf@fosstodon.org 2026-02-20 16:18

    @lholten@hachyderm.io I said "In the same file as the type", but I don't think I would necessarily be consistent about it.

    Open ##2762568

  • @llogiq@hachyderm.io 2026-02-20 17:19

    @lholten@hachyderm.io missing an "it depends" option for the senior devs here... Kidding aside, I would make it dependent on whether the user should care about the trait or the type. E.g. if the trait is just used internally, I'd put its impls together with the definition, unless the file would get too big.

    Open ##2762570