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 Struct

FieldAttributes

Public Struct
std.lang.Type.Struct.FieldAttributes
pub const FieldAttributes = struct

Fields

@"comptime": bool = false
@"align": ?usize = null

null means the field alignment is not explicitly specified. The field will still be aligned to at least @alignOf the field type.

default_value_ptr: ?*const anyopaque = 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.

Functions

pub inline fn defaultValue(comptime attrs: FieldAttributes, comptime FieldType: type) ?FieldType

File

lang.zig:765
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
        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.*;
            }
        }