wit_bindgen/examples/
_3_world_exports.rs

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
crate::generate!({
    inline: r#"
        package example:world-exports;

        world with-exports {
            import log: func(msg: string);

            export run: func();

            /// An example of exporting an interface inline naming it directly.
            export environment: interface {
                get: func(var: string) -> string;
                set: func(var: string, val: string);
            }

            /// An example of exporting an interface defined in this file.
            export units;

            /// An example of exporting an interface defined in a dependency.
            export wasi:random/insecure@0.2.0;
        }

        interface units {
            use wasi:clocks/monotonic-clock@0.2.0.{duration};

            /// Renders the number of bytes as a human readable string.
            bytes-to-string: func(bytes: u64) -> string;

            /// Renders the provided duration as a human readable string.
            duration-to-string: func(dur: duration) -> string;
        }
    "#,

    // provided here to get the export macro rendered in documentation, not
    // required for external use.
    pub_export_macro: true,

    // provided to specify the path to `wasi:*` dependencies referenced above.
    path: "wasi-cli@0.2.0.wasm",

    // specify that these interface dependencies should be generated as well.
    with: {
        "wasi:random/insecure@0.2.0": generate,
        "wasi:clocks/monotonic-clock@0.2.0": generate,
        "wasi:io/poll@0.2.0": generate
    }
});