---
title: "IoStruct: TypeShade 셰이더 API의 레이아웃 분류 인터페이스 참조 문서"
description: "IoStruct, TypeShade API의 레이아웃 분류에 속하는 인터페이스입니다. ioStruct가 반환하는 핸들입니다. 스테이지 경계를 넘는 구조체이며, 필드에 @builtin 또는 @location 속성이 붙습니다."
url: https://typeshade.dev/ko/api/iostruct-interface/
language: ko
---

# `IoStruct`

인터페이스, 레이아웃 분류

ioStruct가 반환하는 핸들입니다. 스테이지 경계를 넘는 구조체이며, 필드에 `@builtin` 또는 `@location` 속성이 붙습니다.

`import type { IoStruct } from 'typeshade'`
`import type { IoStruct } from 'typeshade/core/ir'`

설명은 커밋 af54ddad5의 검토된 컴파일러 문서를 번역한 것입니다. 시그니처와 예제 코드는 원문을 따르며, 필요한 경우 설명에 편집상 수정이 반영됩니다.

## 구문

```ts
interface IoStruct<F extends Record<string, FieldSpec>, 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<NonNullable<F[K]>['type']>> } & { readonly $: ReadonlyNode<`struct:${N}`>; };
  of(node: ReadonlyNode): { readonly [K in keyof F]-?: ReadonlyNode<KeyOf<NonNullable<F[K]>['type']>>; } & { readonly $: ReadonlyNode<`struct:${N}`>; };
  var(name?: string): { readonly [K in keyof F]-?: Node<KeyOf<NonNullable<F[K]>['type']>> } & { readonly $: ReadonlyNode<`struct:${N}`>; };
  construct(values: { readonly [K in keyof F]: ReadonlyNode<KeyOf<NonNullable<F[K]>['type']>>; }): Node<`struct:${N}`>;
}
```

## 설명

[`ioStruct`](https://typeshade.dev/ko/api/iostruct/)가 반환하는 핸들입니다. 스테이지 경계를 넘는 구조체입니다(버텍스 출력, 프래그먼트 입력, 컴퓨트 IO 레코드). 필드에는 `@builtin` 또는 `@location` 속성이 붙습니다. 이 핸들은 `module({ structs })`에 넣는 `StructDecl`, 구조체의 `ShaderType`, 이 모양의 노드에서 타입이 지정된 필드를 읽는 프록시, 식 하나짜리 생성자를 묶습니다. 스테이지 경계를 넘지 않는 구조체(스토리지 버퍼 요소, 중첩 구조체)에는 [`PlainStruct`](https://typeshade.dev/ko/api/plainstruct/)를 씁니다. PlainStruct의 필드에는 속성이 없습니다. 두 핸들의 차이는 이것뿐입니다.

## 인스턴스 속성

**`decl` 읽기 전용 `StructDecl`**

구조체 선언입니다. `module({ structs })`에 넣습니다.

**`type` 읽기 전용 `{ readonly kind: 'struct'; readonly name: N }`**

구조체의 `ShaderType`입니다. 이름을 리터럴로 담으므로, 이 핸들로 만든 모든 값은 [`typeKey`](https://typeshade.dev/ko/api/typekey/)가 만드는 정확한 `struct:${N}` 키를 가집니다.

## 인스턴스 메서드

**`of` ``(node: Node): { readonly [K in keyof F]-?: Node<KeyOf<NonNullable<F[K]>['type']>> } & { readonly $: ReadonlyNode<`struct:${N}`>; }``**

이 구조체 값의 필드에 타입이 지정된 상태로 접근합니다. `VsOut.of(node).uv`는 `member(node, 'uv', <its type>)`와 같은 멤버 읽기입니다. 필드 이름과 타입을 검사합니다. 뷰의 쓰기 권한은 기반을 따릅니다. 변경 가능한 기반(`Var`)은 `Node` 필드를 주며 `.assign(...)`을 받고, 읽기 전용 기반(매개변수, `Let`)은 `ReadonlyNode` 필드를 줍니다. `.$`는 원시 구조체 값입니다. 조건에 따라 펼치는 필드(`...(cond ? { pick } : {})`)는 있는 것으로 타입이 정해지므로, 선택적 출력 필드도 일반 필드로 남습니다.

**`of` ``(node: ReadonlyNode): { readonly [K in keyof F]-?: ReadonlyNode<KeyOf<NonNullable<F[K]>['type']>>; } & { readonly $: ReadonlyNode<`struct:${N}`>; }``**

**`var` ``(name?: string): { readonly [K in keyof F]-?: Node<KeyOf<NonNullable<F[K]>['type']>> } & { readonly $: ReadonlyNode<`struct:${N}`>; }``**

이 구조체의 `var`를 선언하고 타입이 지정된 필드 프록시를 한 단계로 돌려줍니다: `const o = VsOut.var()`. `o.uv.assign(...)`으로 필드에 대입하고, `o.$`로 원시 값을 돌려주거나 넘깁니다. `name`은 생성되는 WGSL 식별자를 고정합니다.

**`construct` ``(values: { readonly [K in keyof F]: ReadonlyNode<KeyOf<NonNullable<F[K]>['type']>>; }): Node<`struct:${N}`>``**

필드 이름을 키로 삼아 이 구조체의 값을 식 하나로 만듭니다. 값은 필드 선언 순서대로 놓이며, 필드가 빠지거나 잘못되면 `tsc` 오류입니다.

## 함께 보기

- [`ioStruct`](https://typeshade.dev/ko/api/iostruct/)
- [`PlainStruct`](https://typeshade.dev/ko/api/plainstruct/)
- [`typeKey`](https://typeshade.dev/ko/api/typekey/)

## 소스

[`src/core/sot.ts`, 345행](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/sot.ts#L345), 커밋 af54ddad5 기준
