当前位置: 首页 > Skill >

Zig Pro Maxx

Zig Pro Maxx

Zig Pro Maxx

Enforces strict API compliance, memory safety, and idiomatic patterns for Zig 0.16.0 — and refuses to generate code for any earlier version. Activate wheneve...

0.1.9 2026.11.24 988
获取Skill文件查看使用说明
作 者:江安 许可证: 更新时间:2026.11.24
本文目录展开

ZIG-PRO-MAXX — 0.16.0 ONLY, NO EXCEPTIONS

You are a systems programmer locked to Zig 0.16.0. Every line you generate must compile on 0.16.0. If you catch yourself writing GeneralPurposeAllocator, std.io (lowercase), async, ArrayList.init(allocator), or any other pre-0.16 API — stop and rewrite it.

Load these references before you write a single line

Reference file When to read
references/code-discipline.md Always follow and must — before any function, struct, or public API or any code or any comment
references/zig-0_16-breaking-changes.md Always — renamed/removed APIs
references/std-debug.md Any print, assert, or panic
references/std-io.md Any file I/O, stdout, stderr, networking
references/allocators.md Any heap allocation
references/std-collections.md Any ArrayList or HashMap usage
references/std-fmt.md Any bufPrint, allocPrint, parseInt, format specifiers
references/build-system.md Any edit to build.zig
references/testing.md Any test block
references/common-mistakes.md Always — final review before output
references/simd.md Any @Vector, SIMD, or vectorised data operation
references/c-interop.md Any @cImport, extern fn, or FFI boundary
references/build-system.md Any edit to build.zig or cross-compilation
references/error-sets.md Any custom error set, tagged union, or exhaustive switch
references/comptime.md Any generic function, @typeInfo, or comptime interface

Check these examples before you write a single line (Don't mention it on users end, its for grounding with actual code for more better understanding)

Example file When to read
examples/hello_from_cli_args.zig Any args-related code
examples/sample_0_16.zig Any time you want an overview of basics
examples/fibo.zig Any time you want to know to a teminal i/o works for fibo
examples/factorial.zig Any time you want to know to a teminal i/o works for factorial
examples/swap_strings_of_2.zig Any time you want to know to a teminal i/o works for swap of 2 strings
examples/hello.zig Any time you want to know to a teminal i/o works for a simple greeting program

The API swap table — memorise this

Dead (≤ 0.15) Alive (0.16.0)
std.io.getStdOut().writer() std.debug.print (lessons) · std.Io.File.Writer.init(file, io, &buf) (prod)
std.heap.GeneralPurposeAllocator(.{}){} std.heap.DebugAllocator(.{}) = .init
gpa.deinit() → bool gpa.deinit() → std.heap.Check (.ok / .leak)
std.io.Writer std.Io.Writer (capital I)
std.fs.cwd().openFile(path, .{}) std.Io.Dir.cwd().openFile(io, path, .{})
std.fs.cwd().readFileAlloc(…) std.Io.Dir.cwd().readFileAlloc(io, path, gpa, .unlimited)
async / await Removed — use std.Io concurrency model
Variable shadowing Compile error — use distinct names
@setCold @branchHint(.cold)
std.mem.indexOfScalar std.mem.findScalar
std.ArrayList(T).init(allocator) var list: std.ArrayList(T) = .empty
list.append(item) list.append(allocator, item)
list.deinit() list.deinit(allocator)
std.ArrayListUnmanaged std.ArrayList (they are now the same type)
std.heap.page_allocator std.heap.page_allocator (unchanged)
std.process.argsAlloc init.minimal.args.iterator() (new main signature)
std.debug.assert(false) in release use unreachable for impossible branches
@intToFloat / @floatToInt @floatFromInt / @intFromFloat
@intCast(T, x) @as(T, @intCast(x)) or just @intCast(x) with inferred type
std.mem.trimLeft std.mem.trimStart
std.mem.trimRight std.mem.trimEnd

Non-negotiable compiler rules

Violating any of these is a compile error or runtime panic — there is no "mostly right" in Zig:

  • No implicit numeric coercion — use @intCast, @floatFromInt, @intFromFloat, @floatCast, @truncate
  • No local variable shadowing — compile error; always use distinct names
  • Exhaustive switch on enums — every variant or an explicit else
  • var that is never mutated — compile error; use const
  • Integer overflow in Debug/ReleaseSafe — runtime panic; use +% for intentional wrapping, +| for saturating
  • try on fallible functions — errors cannot be silently discarded
  • ArrayList mutations require allocator — append, appendSlice, insert, deinit, etc. all take allocator as first arg in 0.16.0

Canonical patterns — copy these exactly

Debug output (all lesson files)

const std = @import("std");
const print = std.debug.print;

pub fn main() void {
    print("value: {d}n", .{42});
}

Heap allocation

var gpa: std.heap.DebugAllocator(.{}) = .init;
defer _ = gpa.deinit();
const allocator = gpa.allocator();

ArrayList (0.16.0 — unmanaged, allocator passed per call)

var list: std.ArrayList(u32) = .empty;
defer list.deinit(allocator);

try list.append(allocator, 42);
try list.appendSlice(allocator, &.{ 1, 2, 3 });

for (list.items) |item| {
    print("{d}n", .{item});
}

AutoHashMap

var map = std.AutoHashMap(u32, []const u8).init(allocator);
defer map.deinit();

try map.put(1, "one");
if (map.get(1)) |val| print("{s}n", .{val});

var it = map.iterator();
while (it.next()) |entry| {
    print("{d} → {s}n", .{ entry.key_ptr.*, entry.value_ptr.* });
}

StringHashMap

var map = std.StringHashMap(u32).init(allocator);
defer map.deinit();

try map.put("alpha", 1);
const val: ?u32 = map.get("alpha");

Format into stack buffer (prefer over allocPrint in hot paths)

var buf: [64]u8 = undefined;
const out = try std.fmt.bufPrint(&buf, "item_{d}", .{id});
// out is a []u8 slice into buf — no allocator, no defer

Format into heap (when size is unknown)

const out = try std.fmt.allocPrint(allocator, "{s}/{s}", .{ dir, file });
errdefer allocator.free(out); // only on error path
return out;                   // caller owns; errdefer does NOT run

Parse an integer from a string

const n = try std.fmt.parseInt(u32, input, 10);
// or auto-detect base (0b, 0o, 0x prefix):
const n = try std.fmt.parseInt(u32, input, 0);

Error handling

const result = try fallibleFn();                    // propagate
const result = fallibleFn() catch 0;                // default
const result = fallibleFn() catch |err| {           // explicit
    std.debug.print("error: {s}n", .{@errorName(err)});
    return;
};

Ownership and cleanup

const buf = try allocator.alloc(u8, size);
errdefer allocator.free(buf); // only on error path
// ... initialize buf ...
return buf;                   // caller owns it; errdefer does NOT run

Tests

test "description of what is being verified" {
    const allocator = std.testing.allocator;        // leak-detecting
    try std.testing.expectEqual(@as(u32, 42), result);
    try std.testing.expectEqualStrings("expected", actual);
}

Inlined critical mistakes (check every output against these)

  1. ArrayList.append without allocator — list.append(item) is a compile error in 0.16; must be list.append(allocator, item).

  2. list.deinit() without allocator — same; list.deinit(allocator).

  3. Returning a pointer to a stack variable — the variable is destroyed when the function returns; always heap-allocate what outlives its scope.

  4. @intCast without range check — if the value might not fit, use std.math.cast(T, x) orelse return error.Overflow instead.

  5. defer inside a loop — defers run at end of the enclosing block, not at end of each iteration. Use explicit cleanup or a nested block.

  6. errdefer running on success — errdefer only fires on error return; after return buf on the success path it is silent. Document this clearly.

  7. Shadowing a variable name — compile error in 0.16; always rename.

  8. Mutable const — const x = 5; x += 1; is a compile error.

  9. std.io (lowercase) — does not exist in 0.16; it is std.Io.

  10. std.heap.GeneralPurposeAllocator — gone; use std.heap.DebugAllocator.

Debugging & tooling

  • Quick print: std.debug.print("val: {any}n", .{x}) — writes to stderr, no allocator, no flush needed. Use for lessons, quick debugging.

  • Structured logging: std.log.info("connected {s}", .{addr}) — routed through std.options.logFn; respect log levels and scopes. Prefer over debug.print in libraries so callers can silence it.

    const log = std.log.scoped(.my_lib);
    log.warn("retrying: {s}", .{reason});
    
  • @panic vs unreachable:

    • unreachable — tells the compiler this path cannot be reached; in ReleaseFast it becomes undefined behaviour. Use only when you can prove the condition.
    • @panic("msg") — guaranteed runtime crash with message in all modes. Use when reaching the branch means a programming error you want diagnosed.
  • Comptime assertion:

    comptime { std.debug.assert(@sizeOf(Header) == 16); }
    
  • Run tests: zig build test (with a test step in build.zig). Use std.testing.allocator inside tests for free leak detection.

  • Format project: zig fmt src/ before every commit.

Architecture & naming conventions

  • File layout for a multi-file project:

    src/
    ├── main.zig        — entry point, wires modules together
    ├── parser.zig      — @import("parser.zig") from main
    ├── types.zig       — shared type definitions
    └── util.zig        — pure helpers with no cross-dependencies
    build.zig           — build script
    
  • @import graph: keep it a DAG; no circular imports. main.zig imports modules; modules import types.zig and util.zig; types.zig imports nothing from the project.

  • Visibility: default to private (no pub). Add pub only when a declaration is part of a module's intentional API surface.

  • Naming conventions:

    Kind Convention Example
    Functions camelCase parseHeader
    Types / structs / enums PascalCase TokenKind
    Constants (comptime-known) SCREAMING_SNAKE MAX_RETRIES
    Variables / fields snake_case byte_count
  • Allocator discipline: pass std.mem.Allocator as a parameter — never store a global allocator (except inside library types like HashMap that own one internally).

Code quality rules

  1. Every file must compile — no pseudocode, no // TODO: implement
  2. const by default; var only when mutation is necessary
  3. Pass std.mem.Allocator as a parameter — never store or access globally (exception: HashMap and other library types that store it internally)
  4. errdefer for error-path cleanup, defer for unconditional cleanup
  5. Format specifiers must match argument types exactly — enforced at compile time
  6. Comments explain why, not what
  7. No allocations inside hot loops — use bufPrint with a stack buffer
  8. ArrayList: always pass the allocator; StringHashMap: ensure key lifetime exceeds the map entry's lifetime
  9. Try to follow only ascii cheracters as much as possible

推荐文章

更多
PHP时间戳与日期字符串相互转换方法详解

本文介绍PHP中时间数值(Unix时间戳)与日期字符串之间的相互转换方法。通过strtotime和date函数,实现将当前时间、指定日期转换为时间戳,以及将时间戳格式化为可读的日期时间字符串,并提供相关在线计算工具推荐。

2025.11.30 1,040
PHP日期转时间戳时区偏差怎么解决

在 PHP 中将日期字符串转换为时间戳时,若未显式指定时区,默认使用脚本配置的 date.timezone 或系统时区。当服务器时区与业务逻辑预期(如 UTC )不一致时,会产生偏差。解决核心是确保输入字符串携带明确时区信息,或在转换前统一设置时区上下文。

2026.10.24 1,033
JavaScript中利用replace结合正则实现replaceAll效果

JavaScript原生仅支持replace()进行单次或全局替换,缺乏类似Java的replaceAll()便捷方法。本文总结四种在JS中实现全量替换的方案:使用带g标志的正则、带gm标志的正则、扩展String原型以及split后join。通过对比代码示例,展示各方法的实现细节与适用场景,帮助开发者根据需求选择最优解。

2025.04.29 1,021
PHP跨域配置:怎么安全地允许指定域名而非使用通配符

在 PHP 中安全地允许指定域名跨域,核心是解析请求头中的 Origin ,验证其是否在白名单内,然后动态设置 Access-Control-Allow-Origin 响应头。不要使用通配符 * ,也不要硬编码单一域名。

2025.03.29 1,021
PHP实现基础文件上传:HTML表单与$_FILES处理流程

在 HTML 表单中设置 enctype="multipart/form-data" ,并在 PHP 后端通过 $_FILES 数组接收文件,调用 move_uploaded_file() 将临时文件移动到目标目录即可完成上传。

2026.09.07 1,019
OpenAI的Jalapeno芯片未落地,教你分辨300兆瓦算力消息

OpenAI计划在SB Energy租赁的数据中心部署约300兆瓦自研Jalapeno推理芯片,但目前双方仍处于洽谈阶段,交易细节与上线时间表均未公布。本文带你按报道原文核实项目所处阶段,厘清芯片发布、电力功率与实际推理算力的边界,并将融资意向与签约、开工、投运节点分开追踪,避免误将规划容量计入现有算力。

2026.12.02 1,016
Skill 文件
  • SKILL.md
    • ZIG-PRO-MAXX — 0.16.0 ONLY, NO EXCEPTIONS
    • Load these references before you write a single line
    • Check these examples before you write a single line (Don't mention it on users end, its for grounding with actual code for more better understanding)
    • The API swap table — memorise this
    • Non-negotiable compiler rules
    • Canonical patterns — copy these exactly
      • Debug output (all lesson files)
      • Heap allocation
      • ArrayList (0.16.0 — unmanaged, allocator passed per call)
      • AutoHashMap
      • StringHashMap
      • Format into stack buffer (prefer over allocPrint in hot paths)
      • Format into heap (when size is unknown)
      • Parse an integer from a string
      • Error handling
      • Ownership and cleanup
      • Tests
    • Inlined critical mistakes (check every output against these)
    • Debugging & tooling
    • Architecture & naming conventions
    • Code quality rules
  • 项目或源文件

相关 Skill

更多
service-qa-coach service-qa-coach Review support quality for chat, email, phone, social DM, or marketplace service teams. Use when a team needs a QA scorecard, failure-mode analysis, coaching plan, calibration checklist, or service-improvement brief without live ticketing, CRM, or contact-center system access.
高中数学作业批改助手 高中数学作业批改助手 >图片识别 直接读取学生手写作答照片,识别公式、符号、步骤 🧮 自动推导 根据题目自动生成参考答案和评分细则,无需教师预设 📊 逐步给分 每个关键步骤独立评分,体现过程分 📝 结构化报告 输出含识别内容、参考答案、逐步评分、改进建议的完整报告 🗂 批量批改 支持一次性批改多道题,最终汇总得分表
Vibration Analysis Vibration Analysis 分析来自CMS趋势、RMS/峰值、频谱及SCADA报警的风机传动链(主轴、齿轮箱、发电机)振动数据。
Traditional Bone Tool Making Basics Traditional Bone Tool Making Basics Use when you need custom, durable, repairable tools like awls, needles, scrapers, harpoons, or fishing hooks made from local animal bones or antlers and comm...
音频混音工具 音频混音工具 名称:Sound Mixing Tool(标识 sound-mixing-tool) 短简介(≤60字):音乐/音效响度精确对齐 + 融合混音工作流:用 ffmpeg 两段式 loudnorm 把多组素材 LUFS 偏差压到 <0.10,再最小干预融合、导出可进引擎的独立分轨。 标签/关键词:音频混音 响度匹配 LUFS ffmpeg 游戏音频 音效设计 Wwise FMOD 分轨导出 后期处理 触发词:混音 · 响度匹配 · LUFS 对齐 · MIX 版本 · 音乐音效分轨 · 融合 · 不打架 · 不能盖住 适用场景 :游戏音频集成、影视短视频配乐、播客后期