authorgravatar for johnnymarler@gmail.comJonathan Marler <johnnymarler@gmail.com> 2019-12-07 12:16:05-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-12 19:01:22-05:00
log4cb4148b350895f74ff57f8c87336dcb08d830b9
tree7aa0b7bfcdb22de555913f43f18d191c93e9b0c4
parent7699b5b997c7a024a6d9558df0ec72d71ef402fe

Document sentinel type in langref


1 files changed, 20 insertions(+), 0 deletions(-)

doc/langref.html.in+20
...@@ -8363,6 +8363,7 @@ pub const TypeInfo = union(TypeId) {...@@ -8363,6 +8363,7 @@ pub const TypeInfo = union(TypeId) {
8363 alignment: comptime_int,8363 alignment: comptime_int,
8364 child: type,8364 child: type,
8365 is_allowzero: bool,8365 is_allowzero: bool,
8366 sentinel: var,
83668367
8367 pub const Size = enum {8368 pub const Size = enum {
8368 One,8369 One,
...@@ -8375,6 +8376,7 @@ pub const TypeInfo = union(TypeId) {...@@ -8375,6 +8376,7 @@ pub const TypeInfo = union(TypeId) {
8375 pub const Array = struct {8376 pub const Array = struct {
8376 len: comptime_int,8377 len: comptime_int,
8377 child: type,8378 child: type,
8379 sentinel: var,
8378 };8380 };
83798381
8380 pub const ContainerLayout = enum {8382 pub const ContainerLayout = enum {
...@@ -8505,6 +8507,24 @@ pub const TypeInfo = union(TypeId) {...@@ -8505,6 +8507,24 @@ pub const TypeInfo = union(TypeId) {
8505 {#link|error sets|Error Set Type#}, the fields are guaranteed to be in the same8507 {#link|error sets|Error Set Type#}, the fields are guaranteed to be in the same
8506 order as declared. For declarations, the order is unspecified.8508 order as declared. For declarations, the order is unspecified.
8507 </p>8509 </p>
8510 <p>
8511 Note that the {#syntax#}sentinel{#endsyntax#} field in {#syntax#}TypeInfo.Pointer{#endsyntax#}
8512 and {#syntax#}TypeInfo.Array{#endsyntax#} is of type {#syntax#}var{#endsyntax#} rather
8513 than {#syntax#}?child{#endsyntax#}. {#syntax#}TypeInfo.Pointer{#endsyntax#}
8514 and {#syntax#}TypeInfo.Array{#endsyntax#} can be constructed with any comptime value for the
8515 {#syntax#}sentinel{#endsyntax#} field. However, the {#syntax#}@Type{#endsyntax#} builtin will
8516 only accept the TypeInfo struct if the sentinel value is implicitly convertible to
8517 {#syntax#}child{#endsyntax#}. Furthermore, any {#syntax#}TypeInfo.Pointer{#endsyntax#}
8518 or {#syntax#}TypeInfo.Array{#endsyntax#} retreived from {#syntax#}@typeInfo{#endsyntax#} will
8519 guarantee that {#syntax#}@typeOf(sentinel){#endsyntax#} is equal to
8520 {#syntax#}?child{#endsyntax#}. For example, {#syntax#}@typeOf(sentinel){#endsyntax#} for a
8521 {#syntax#}TypeInfo.Pointer{#endsyntax#} constructed with
8522 {#syntax#}TypeInfo.Pointer { ... .sentinel = 0; ... }{#endsyntax#} would be
8523 {#syntax#}comptime_int{#endsyntax#} rather than {#syntax#}?u8{#endsyntax#}. However, if you
8524 passed that {#syntax#}TypeInfo.Pointer{#endsyntax#} struct to
8525 {#syntax#}@typeInfo(@Type(myPointerInfo)){#endsyntax#} then {#syntax#}@typeOf(sentinel){#endsyntax#}
8526 would be {#syntax#}?u8{#endsyntax#}.
8527 </p>
8508 {#header_close#}8528 {#header_close#}
85098529
8510 {#header_open|@typeName#}8530 {#header_open|@typeName#}