Skip to content
This repository has been archived by the owner on Dec 27, 2021. It is now read-only.

Hejsil/zig-interface

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This repo is out of date. The current standard library no longer uses @fieldParentPtr interfaces for Allocator and Random, and basically uses what is proposed here.

The current "interface field" pattern in Zig has problems:

  • It's too easy to shoot yourself by copying the interface out of its implementation: #591.
  • It is unfriendly to the optimizer.
  • People don't like this pattern and find it hard to understand.

This repo is an alternative way of having userland interfaces and is designed around the idea that the current interfaces are mostly used to get the helper functions they provide, and not the dynamic dispatch. We, therefore, separate the two.

  • A helper function is just a generic function that expects that the argument passed have certain functions that it can call (could have enhanched validation with #1669).
  • When dynamic dispatch is needed, one can wrap their datastructure in a struct {vtable: *c_void, impl: *c_void} data structure and provide the same interface that the helper functions expect.

What do we gain from this?

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages