Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Union

Type

Public Union
std.lang.Type
pub const Type = union(enum)

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

type: type
void: void
bool: bool
noreturn: noreturn
int: Int
float: Float
pointer: Pointer
array: Array
@"struct": Struct
comptime_float: comptime_float
comptime_int: comptime_int
undefined: undefined
null: null
optional: Optional
error_union: ErrorUnion
error_set: ErrorSet
@"enum": Enum
@"union": Union
@"fn": Fn
@"opaque": Opaque
frame: Frame
@"anyframe": AnyFrame
vector: Vector
enum_literal: enum_literal
spirv: Spirv

Structs

Types

File

lang.zig:641
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
pub const Type = union(enum) {
    type,
    void,
    bool,
    noreturn,
    int: Int,
    float: Float,
    pointer: Pointer,
    array: Array,
    @"struct": Struct,
    comptime_float,
    comptime_int,
    undefined,
    null,
    optional: Optional,
    error_union: ErrorUnion,
    error_set: ErrorSet,
    @"enum": Enum,
    @"union": Union,
    @"fn": Fn,
    @"opaque": Opaque,
    frame: Frame,
    @"anyframe": AnyFrame,
    vector: Vector,
    enum_literal,
    spirv: Spirv,

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const Int = struct {
        signedness: Signedness,
        bits: u16,
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const Float = struct {
        bits: u16,
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const Pointer = struct {
        size: Size,
        attrs: Attributes,
        child: type,

        /// The type of the sentinel is the element type of the pointer, which is
        /// the value of the `child` field in this struct. However there is no way
        /// to refer to that type here, so we use `*const anyopaque`.
        /// See also: `sentinel`
        sentinel_ptr: ?*const anyopaque,

        /// Loads the pointer type's sentinel value from `sentinel_ptr`.
        /// Returns `null` if the pointer type has no sentinel.
        pub inline fn sentinel(comptime ptr: Pointer) ?ptr.child {
            const sp: *const ptr.child = @ptrCast(@alignCast(ptr.sentinel_ptr orelse return null));
            return sp.*;
        }

        /// This data structure is used by the Zig language code generation and
        /// therefore must be kept in sync with the compiler implementation.
        pub const Size = enum(u2) {
            one,
            many,
            slice,
            c,
        };

        /// This data structure is used by the Zig language code generation and
        /// therefore must be kept in sync with the compiler implementation.
        pub const Attributes = struct {
            @"const": bool = false,
            @"volatile": bool = false,
            @"allowzero": bool = false,
            @"addrspace": ?AddressSpace = null,
            @"align": ?usize = null,
        };
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const Array = struct {
        len: comptime_int,
        child: type,

        /// The type of the sentinel is the element type of the array, which is
        /// the value of the `child` field in this struct. However there is no way
        /// to refer to that type here, so we use `*const anyopaque`.
        /// See also: `sentinel`.
        sentinel_ptr: ?*const anyopaque,

        /// Loads the array type's sentinel value from `sentinel_ptr`.
        /// Returns `null` if the array type has no sentinel.
        pub inline fn sentinel(comptime arr: Array) ?arr.child {
            const sp: *const arr.child = @ptrCast(@alignCast(arr.sentinel_ptr orelse return null));
            return sp.*;
        }
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const ContainerLayout = enum(u2) {
        auto,
        @"extern",
        @"packed",
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const Struct = struct {
        is_tuple: bool,
        layout: ContainerLayout,
        /// Always `null` if `layout != .@"packed"`.
        backing_integer: ?type,

        field_names: []const [:0]const u8,
        /// Guaranteed to have the same length as `field_names`.
        field_types: []const type,
        /// Guaranteed to have the same length as `field_names`.
        field_attrs: []const FieldAttributes,

        decl_names: []const [:0]const u8,

        pub const FieldAttributes = struct {
            @"comptime": bool = false,
            /// `null` means the field alignment is not explicitly specified. The field will still
            /// be aligned to at least `@alignOf` the field type.
            @"align": ?usize = null,
            /// The type of the default value is the type of this struct field. However, that type
            /// is not known here, so we use a type-erased pointer instead, which must be cast to
            /// a pointer to the field type.
            ///
            /// See also: `defaultValue`.
            default_value_ptr: ?*const anyopaque = null,

            /// Loads the field's default value from `default_value_ptr`.
            /// `FieldType` must exactly match the corresponding element of `Struct.field_types`.
            /// Returns `null` if the field has no default value.
            pub inline fn defaultValue(comptime attrs: FieldAttributes, comptime FieldType: type) ?FieldType {
                const dp: *const FieldType = @ptrCast(@alignCast(attrs.default_value_ptr orelse return null));
                return dp.*;
            }
        };
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const Optional = struct {
        child: type,
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const ErrorUnion = struct {
        error_set: type,
        payload: type,
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const ErrorSet = struct {
        error_names: ?[]const [:0]const u8,
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const Enum = struct {
        tag_type: type,
        mode: Mode,

        field_names: []const [:0]const u8,
        /// Guaranteed to have the same length as `field_names`.
        field_values: []const comptime_int,

        decl_names: []const [:0]const u8,

        /// This data structure is used by the Zig language code generation and
        /// therefore must be kept in sync with the compiler implementation.
        pub const Mode = enum { exhaustive, nonexhaustive };
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const Union = struct {
        layout: ContainerLayout,
        tag_type: ?type,
        /// Always `null` if `layout != .@"packed"`.
        backing_integer: ?type,

        field_names: []const [:0]const u8,
        /// Guaranteed to have the same length as `field_names`.
        field_types: []const type,
        /// Guaranteed to have the same length as `field_names`.
        field_attrs: []const FieldAttributes,

        decl_names: []const [:0]const u8,

        pub const FieldAttributes = struct {
            /// `null` means the field alignment is not explicitly specified. The field will still
            /// be aligned to at least `@alignOf` the field type.
            @"align": ?usize = null,
        };
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const Fn = struct {
        attrs: Attributes,
        is_generic: bool,
        /// `null` means the return type is generic, i.e. it depends on a function argument.
        return_type: ?type,

        /// A `null` element represents either an `anytype` parameter, or a parameter with a generic
        /// type, i.e. where the type depends on a previous function argument.
        param_types: []const ?type,
        /// Guaranteed to have the same length as `param_types`.
        param_attrs: []const ParamAttributes,

        pub const ParamAttributes = struct {
            @"noalias": bool = false,
        };

        pub const Attributes = struct {
            @"callconv": CallingConvention = .auto,
            varargs: bool = false,
        };
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const Spirv = union(enum(u2)) {
        sampler,
        image: Image,
        sampled_image: type,
        runtime_array: type,

        pub const Image = struct {
            usage: Usage,
            format: Format,
            dim: Dimensionality,
            depth: Depth,
            access: Access,
            arrayed: bool,
            multisampled: bool,

            pub const Usage = union(enum(u2)) {
                unknown: type,
                sampled: type,
                storage: type,
            };

            pub const Format = enum(u4) {
                unknown,
                rgba32f,
                rgba32i,
                rgba32u,
                rgba16f,
                rgba16i,
                rgba16u,
                rgba8unorm,
                rgba8snorm,
                rgba8i,
                rgba8u,
                r32f,
                r32i,
                r32u,
            };

            pub const Dimensionality = enum(u2) {
                @"1d",
                @"2d",
                @"3d",
                cube,
            };

            pub const Depth = enum(u2) { unknown, depth, not_depth };

            pub const Access = enum(u2) { unknown, read_only, write_only, read_write };
        };
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const Opaque = struct {
        decl_names: []const [:0]const u8,
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const Frame = struct {
        function: *const anyopaque,
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const AnyFrame = struct {
        child: ?type,
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const Vector = struct {
        len: comptime_int,
        child: type,
    };
}