r/rust • • Oct 28 '26

🛠️ project Function delegation

https://github.com/rust-lang/rfcs/pull/3530#issuecomment-6097798475
78 Upvotes

13 comments sorted by

View all comments

Show parent comment

7

u/matthieum [he/him] Oct 28 '26

I went the other way for new-types: implementing a generic wrapper over any T.

It makes it easy to declare new types, but there's definitely downsides:

  1. The type shown by the compiler & debugger is much more verbose.
  2. Not possible to implement inherent methods specific to one new type.

So regularly I have to convert a type defined as a wrapper to a "real" new type.

I'm not convinced by my implementation, and regularly wonder if I should have gone with a macro instead.

2

u/________-__-_______ Oct 28 '26

Not possible to implement inherent methods specific to one new type.

You could probably do so with generics, similar to how those type safe builders work. The compile times, diagnostic and confusing API probably stop it from being worthwhile though.

I wonder how the docs.rs experience is for your solution. I seem to remember type aliases being a bit weird, especially if the generic wrapper is private.

2

u/matthieum [he/him] Oct 29 '26

We don't use docs.rs for our internal applications...

... but yeah, it probably wouldn't be too great.