Zig's New Writer
10 months ago
- #Zig
- #API
- #Programming
- Zig's Io namespace is being reworked, including the Writer and Reader interfaces.
- The new Writer interface is std.Io.Writer, requiring a drain function for custom implementations.
- Buffering is built into std.Io.Writer, with options to use or bypass it.
- Custom writers can implement a simplified drain method, ignoring the splat parameter.
- File.Writer is a struct that includes the std.Io.Writer interface, following a convention.
- The Writer interface consolidates various writer-related methods, replacing older functions like std.fmt.formatIntBuf.
- Legacy writers need an adaptToNewApi method to upgrade to the new interface.
- The change integrates buffering directly into the Writer, differing from the compositional approach used in other languages.