PlainStruct
Interface in Layout
The handle structDecl returns: a struct declared for something other than a stage's IO boundary, such as a storage-buffer element type (paired with storageBuffer) or a struct nested inside another struct.
import type { PlainStruct } from 'typeshade'
The signature, the description and the examples come from the compiler's own source at commit 26de7be8.
Syntax
interface PlainStruct<F extends Record<string, ShaderType>, N extends string = string> { readonly decl: StructDecl; readonly type: { readonly kind: 'struct'; readonly name: N }; of(node: Node): { readonly [K in keyof F]: Node<KeyOf<F[K]>> } & { readonly $: ReadonlyNode<`struct:${N}`>; }; of(node: ReadonlyNode): { readonly [K in keyof F]: ReadonlyNode<KeyOf<F[K]>> } & { readonly $: ReadonlyNode<`struct:${N}`>; }; get<K extends keyof F & string>(node: ReadonlyNode, field: K): ReadonlyNode<KeyOf<F[K]>>; var(name?: string): { readonly [K in keyof F]: Node<KeyOf<F[K]>> } & { readonly $: ReadonlyNode<`struct:${N}`>; }; construct(values: { readonly [K in keyof F]: ReadonlyNode<KeyOf<F[K]>> }): Node<`struct:${N}`>;}Description
Fields are plain
ShaderTypes with no @location or @builtin attribute; IoStruct is the twin
that carries those. It has the same shape as IoStruct (.decl, .type, .of, .var,
.construct) plus a positional .get(node, field) reader.
Instance properties
declread onlyStructDeclThe struct declaration, for
module({ structs }).typeread only{ readonly kind: 'struct'; readonly name: N }The struct’s
ShaderType, carrying the name as a literal so every value built from this handle has the exactstruct:${N}keytypeKeyproduces.
Instance methods
of(node: Node): { readonly [K in keyof F]: Node<KeyOf<F[K]>> } & { readonly $: ReadonlyNode<`struct:${N}`>; }Typed field access on a struct value you hold as a raw node:
Seg.of(someNode).p0. A storage-buffer element does not need it, becausebuf.at(i)already returns this proxy. The view’s write capability follows the base: a mutable base givesNodefields, a read-only base givesReadonlyNodefields..$is the raw struct value, which can be passed on to a function that takes the struct.of(node: ReadonlyNode): { readonly [K in keyof F]: ReadonlyNode<KeyOf<F[K]>> } & { readonly $: ReadonlyNode<`struct:${N}`>; }get<K extends keyof F & string>(node: ReadonlyNode, field: K): ReadonlyNode<KeyOf<F[K]>>Positional field access:
Seg.get(node, 'p0')is the same read asSeg.of(node).p0, with a wrong field name atscerror. It suits a call site that reads many fields through one shorthand (const g = Seg.get). It is a read accessor and returnsReadonlyNode.var(name?: string): { readonly [K in keyof F]: Node<KeyOf<F[K]>> } & { readonly $: ReadonlyNode<`struct:${N}`>; }Declare a
varof this struct and return its typed, mutable field proxy, asIoStruct.vardoes.construct(values: { readonly [K in keyof F]: ReadonlyNode<KeyOf<F[K]>> }): Node<`struct:${N}`>Build a value of this struct in one expression, keyed by field name and placed in declaration order, as
IoStruct.constructdoes.
See also
Source
src/core/sot.ts, line 481, at commit 26de7be8