-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.wit
More file actions
83 lines (64 loc) · 2.1 KB
/
example.wit
File metadata and controls
83 lines (64 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package rib:language-guide@0.1.0;
// Example WIT for docs/language-guide.md (documentation only; not built by default).
interface inventory {
/// Integer point (record).
record point {
x: s32,
y: s32,
}
/// Stock line (record with string + integer).
record line-item {
sku: string,
qty: u32,
}
/// Order lifecycle (enum — mutually exclusive named cases).
enum order-stage {
draft,
placed,
shipped,
}
/// Payment outcome (variant — tagged union with different payloads).
variant payment-info {
card(string),
wallet,
failed(string),
}
/// Permission bits (flags — independent booleans).
flags file-access {
read,
write,
execute,
}
/// Manhattan distance from origin: |x| + |y|
length: func(p: point) -> s32;
/// True if quantity is under 1000 (example predicate).
validate-qty: func(qty: u32) -> bool;
/// Optional product label for an id.
lookup-sku: func(id: s32) -> option<string>;
/// Integer division, or an error message.
ratio: func(a: s32, b: s32) -> result<s32, string>;
/// Render enum as a short label.
format-stage: func(stage: order-stage) -> string;
/// Describe a payment variant as text.
summarize-payment: func(p: payment-info) -> string;
/// Construct a line item from parts.
make-item: func(sku: string, qty: u32) -> line-item;
/// Toy summary of which flags are set (embedding may return any string).
describe-access: func(f: file-access) -> string;
}
/// Shopping-cart style **resource** (per-cart state, constructor, methods).
/// Rib: e.g. `let my-instance = instance();` then `let store-main = my-instance.cart("store-main");` → `store-main.add-line` / `line-count` (kebab exports).
interface shopping {
use inventory.{line-item};
resource cart {
/// Host may treat this string as a logical cart key (e.g. store or session id).
constructor(id: string);
/// Illustrative counter — embedder returns how many lines were added for this cart.
line-count: func() -> u32;
add-line: func(item: line-item);
}
}
world guide-demo {
export inventory;
export shopping;
}