nilslice / zig-interface

A compile-time interface checker for Zig that enables interface-based design with comprehensive type checking and detailed error reporting.
MIT License
50 stars 1 forks source link

Automatic interface satisfying check #2

Open adex-codez opened 2 weeks ago

adex-codez commented 2 weeks ago

For every type which implements an interface an automatic check for if the type implements the interface like go's interface

nilslice commented 1 week ago

How do you propose creating an automatic check? I could be missing your question, sorry. But this function (satisfiedBy) exists on the Interface you create to check:

const Repository = Interface(.{...});

// In functions that accept interface implementations:
fn createUser(repo: anytype, name: []const u8, email: []const u8) !User {
    comptime Repository.satisfiedBy(@TypeOf(repo));
    // ... rest of implementation
}

// Or verify directly:
comptime Repository.satisfiedBy(InMemoryRepository); // where `InMemoryRepository` is the struct implementing `Repository`