# Mixin alternative using const declarations

**URL:** <https://ziggit.dev/t/mixin-alternative-using-const-declarations/6091>\
**Category:** Brainstorming\
**Tags:** language\
**Created:** [September 22, 2024, 7:22pm UTC](https://ziggit.dev/t/mixin-alternative-using-const-declarations/6091 "2024-09-22T19:22:23Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![AndrewCodeDev](https://ziggit.dev/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@AndrewCodeDev](https://ziggit.dev/u/AndrewCodeDev)\
**Post date:** [September 22, 2024, 7:25pm UTC](https://ziggit.dev/t/mixin-alternative-using-const-declarations/6091/2 "2024-09-22T19:25:37Z")

</div>

Just to note, you can extend this quite easily using `comptime` function parameters that take in your meta-functions to be specialized. The `Bar` example is highly trivial but it matches our use case for Fluent - not true in general but just for demonstration’s sake.

A little more involved would be something like so… (pseudo-code):

```zig
pub fn MyImpl(comptime Self: type) type {
    return struct {
        pub fn foo(self: Self, ...) ...
        pub fn bar(self: Self, ...) ...
    };
}

pub fn Thing(comptime T: type, comptime Impl: anytype) type {
    return struct {
        const Self = @This();     
        const foo = Impl(Self).foo;
        const bar = Impl(Self).bar;
    };
}

const Widget = Thing(u8, MyImpl);

```

The major difference is there’s no “silent-injection” as it were. You have to specifically declare `foo, bar, etc...` in the interface.

---

_[View the full topic](https://ziggit.dev/t/mixin-alternative-using-const-declarations/6091)._
