Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

WIT 리소스 사용하기

이 섹션에서는 WIT 리소스를 사용하는 방법에 대한 언어별 가이드를 제공합니다.

리소스는 컴포넌트 경계의 한쪽에서만 구현되는 기능을 나타냅니다. 예를 들어 다른 컴포넌트나 기반 플랫폼/호스트에서 구현되는 기능이 이에 해당합니다.

리소스의 예는 다음과 같습니다.

package docs:calc-resource@0.1.0;

interface types {
    enum operation {
        add,
        sub,
        mul,
        div,
    }

    variant execute-error {
        divide-by-zero,
        unexpected(string),
    }

    resource stack-calculator {
        constructor();
        push-operand: func(operand: u32);
        push-operation: func(operation: operation);
        execute: func() -> result<u32, error>;
    }
}

world calculator {
    export types;
}

위의 스택 기반 계산기를 구현하는 호스트나 컴포넌트는 해당 기능을 import하는 컴포넌트와 리소스(stack-calculator 엔티티)를 공유하지만, 실제 구현은 공유하지 않습니다. stack-calculator 리소스에 대한 모든 호출은 해당 기능을 export한 컴포넌트 내부에서 처리됩니다.

언어

이 가이드는 다음과 같은 여러 언어로 구현되어 있습니다.

언어
Rust

원문 © 2023 The Bytecode Alliance Contributors · WebAssembly Components Documentation · CC BY 4.0
Yeokja 한국어 번역·편집 · Anthropic 사의 claude-sonnet-5 모델을 활용하여 번역되었으며 학습을 모두 비허용한 상태로 작업하였습니다 · 이 번역은 원문을 수정한 문서이며 CC BY 4.0으로 제공합니다.