| It'd be a bit gnarly, but somebody could absolutely write a utility capable of providing those features in the userspace of the language: 1. Documented Interface: Documentation would be a struct with the desired function declarations (combined with some type-checking, I spit-balled an idea for that recently [0]). 2. Default Function Implementations: The exact tool you'll use will vary since the language hasn't hit 1.0, but a `pub usingnamespace FakeInheritanceFooBarBaz(TheTrait, @This());` could have the desired effect. 3. Stored in other structs: Rust doesn't even really give you this. It has syntactic sugar to make the dynamic case easier, and it has the ability to store concrete implementations. For the latter, Zig just works. For the former, you want something that automagically wraps any trait-conforming object in a dynamic pointer-based structure. That's a weak point in the language since the metaprogramming facilities for creating functions and for creating objects with decls aren't very solid (that will get fixed by 1.0). You could make do for now by using comptime fields instead of decls in the wrapper logic that generates this thing (think `foo: fn (A) B` instead of `fn foo(A) B {}`), and that generation code would have to handle different argument counts by hand. 4. Monomorphization: You'd get that for free, since this is just ordinary comptime duck-typing. 5. Dynamic (runtime dispatch: This is really identical to the work for (3). [0] https://news.ycombinator.com/item?id=42899354 |
How would you clean up Writer in std?