Skip to content

Commit 85a595b

Browse files
author
Jonathan Marler
committed
Document sentinel type in langref
1 parent 05fc4d3 commit 85a595b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

doc/langref.html.in

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8351,6 +8351,7 @@ pub const TypeInfo = union(TypeId) {
83518351
alignment: comptime_int,
83528352
child: type,
83538353
is_allowzero: bool,
8354+
sentinel: var,
83548355

83558356
pub const Size = enum {
83568357
One,
@@ -8363,6 +8364,7 @@ pub const TypeInfo = union(TypeId) {
83638364
pub const Array = struct {
83648365
len: comptime_int,
83658366
child: type,
8367+
sentinel: var,
83668368
};
83678369

83688370
pub const ContainerLayout = enum {
@@ -8493,6 +8495,24 @@ pub const TypeInfo = union(TypeId) {
84938495
{#link|error sets|Error Set Type#}, the fields are guaranteed to be in the same
84948496
order as declared. For declarations, the order is unspecified.
84958497
</p>
8498+
<p>
8499+
Note that the {#syntax#}sentinel{#endsyntax} field in {#syntax#}TypeInfo.Pointer{#endsyntax#}
8500+
and {#syntax#}TypeInfo.Array{#endsyntax#} is of type {#syntax#}var{#endsyntax#} rather
8501+
than {#syntax#}?child{#endsyntax#}. {#syntax#}TypeInfo.Pointer{#endsyntax#}
8502+
and {#syntax#}TypeInfo.Array{#endsyntax#} can be constructed with any comptime value for the
8503+
{#syntax#}sentinel{#endsyntax} field. However, the {#syntax#}@Type{#endsyntax#} builtin will
8504+
only accept the TypeInfo struct if the sentinel value is implicitly convertible to
8505+
{#syntax#}child{#endsyntax#}. Furthermore, any {#syntax#}TypeInfo.Pointer{#endsyntax#}
8506+
or {#syntax#}TypeInfo.Array{#endsyntax#} retreived from {#syntax#}@typeInfo{#endsyntax#} will
8507+
guarantee that {#syntax#}@typeOf(sentinel){#endsyntax#} is equal to
8508+
{#syntax#}?child{#endsyntax#}. For example, {#syntax#}@typeOf(sentinel){#endsyntax} for a
8509+
{#syntax#}TypeInfo.Pointer{#endsyntax#} constructed with
8510+
{#syntax#}TypeInfo.Pointer { ... .sentinel = 0; ... }{#endsyntax#} would be
8511+
{#syntax#}comptime_int{#endsyntax#} rather than {#syntax#}?u8{#endsyntax#}. However, if you
8512+
passed that {#syntax#}TypeInfo.Pointer{#endsyntax#} struct to
8513+
{#syntax#}@typeInfo(@Type(myPointerInfo)){#endsyntax#} then {#syntax#}@typeOf(sentinel){#endsyntax}
8514+
would be {#syntax#}?u8{#endsyntax#}.
8515+
</p>
84968516
{#header_close#}
84978517

84988518
{#header_open|@typeName#}

0 commit comments

Comments
 (0)