structstd.builtin.Type.Pointer[src]

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

Fields

size: Size
is_const: bool
is_volatile: bool
alignment: comptime_int

TODO make this u16 instead of comptime_int

address_space: AddressSpace
child: type
is_allowzero: bool
sentinel_ptr: ?*const anyopaque

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

Functions

Functionsentinel[src]

pub inline fn sentinel(comptime ptr: Pointer) ?ptr.child

Loads the pointer type's sentinel value from sentinel_ptr. Returns null if the pointer type has no sentinel.

Parameters

ptr: Pointer

Source Code

Source code
pub inline fn sentinel(comptime ptr: Pointer) ?ptr.child {
    const sp: *const ptr.child = @ptrCast(@alignCast(ptr.sentinel_ptr orelse return null));
    return sp.*;
}

Source Code

Source code
pub const Pointer = struct {
    size: Size,
    is_const: bool,
    is_volatile: bool,
    /// TODO make this u16 instead of comptime_int
    alignment: comptime_int,
    address_space: AddressSpace,
    child: type,
    is_allowzero: bool,

    /// 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,
    };
}