0Pricing
Zig Academy · Ders

@typeInfo ile Alanları İnceleme

Bir türün yapısını derleme zamanında inceleyin.

@typeInfo ile Alanları İnceleme, CoddyKit'te ücretsiz bir Zig Academy dersidir. Bu, 4 dersinin 1. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Zig Academy öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Zig Academy kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

Look Inside Any Type

Zig lets your code examine its own types while it compiles. The built-in @typeInfo hands you the full structure of a type as data. 🔎

It Returns a Type.Info Value

@typeInfo takes a type and returns a std.builtin.Type value. That value is a tagged union describing exactly what kind of type you passed.

const info = @typeInfo(u32);

The Tag Says What Kind It Is

The union tag tells you the category: a struct, an int, a pointer, and so on. You switch on it to react to each kind of type.

switch (@typeInfo(T)) {
    .Struct => {},
    else => {},
}

Reach the Struct Payload

When the type is a struct, the .Struct variant carries a payload describing its fields, declarations, and layout.

const s = @typeInfo(Point).Struct;

Fields Live in an Array

The struct payload has a fields array. Each entry is a StructField holding one field's name, type, and other details.

const fields = @typeInfo(Point).Struct.fields;

Read a Field's Name and Type

Each StructField exposes a name string and a type. Both are compile-time values you can print or branch on.

const f = @typeInfo(Point).Struct.fields[0];
const n = f.name;

Walk Fields with inline for

Because the field list is comptime, you iterate it with inline for. The loop unrolls, giving each field its own concrete code.

inline for (@typeInfo(T).Struct.fields) |field| {
    _ = field.name;
}

Inspect Integer Types Too

For an int, the .Int variant reveals its signedness and bit width, so you can adapt logic to the exact number type.

const i = @typeInfo(i16).Int;
const bits = i.bits;

Enums Expose Their Members

The .Enum variant lists every enum field with its name and integer value, letting you generate code per option.

const e = @typeInfo(Color).Enum;
const fields = e.fields;

Pointers Reveal Their Target

For pointers the .Pointer variant tells you the child type, size kind, and whether it is const, so you can unwrap layers.

const p = @typeInfo(*u8).Pointer;
const child = p.child;

This Powers Real Libraries

Reflection drives Zig's own JSON and formatting code: they read fields with @typeInfo and handle any struct you give them. ✨

Quick Check

You want the list of a struct's fields at compile time. Which expression gives it to you?

Recap

@typeInfo turns a type into data: switch on its tag, then read fields, bits, or members and loop them with inline for. 🎯

Sıkça Sorulan Sorular

“@typeInfo ile Alanları İnceleme” dersi ücretsiz mi?

Evet — “@typeInfo ile Alanları İnceleme” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Zig Academy kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Zig Academy kursu toplamda 4 dersten oluşur.

“@typeInfo ile Alanları İnceleme” dersinde ne öğreneceğim?

Bir türün yapısını derleme zamanında inceleyin. Zig Academy ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

Zig Academy öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Zig Academy, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 1. dersidir.

“@typeInfo ile Alanları İnceleme” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu Zig Academy dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Zig Academy dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. @typeInfo ile Alanları İnceleme
  2. @Type ile Türler Oluşturma
  3. Derleme Zamanı Doğrulama ve @compileError
  4. comptime ile Kod Üretme
← Zig Academy Sayfasına Dön