wit_bindgen/examples/
_3_world_exports.rs

1crate::generate!({
2    inline: r#"
3        package example:world-exports;
4
5        world with-exports {
6            import log: func(msg: string);
7
8            export run: func();
9
10            /// An example of exporting an interface inline naming it directly.
11            export environment: interface {
12                get: func(var: string) -> string;
13                set: func(var: string, val: string);
14            }
15
16            /// An example of exporting an interface defined in this file.
17            export units;
18
19            /// An example of exporting an interface defined in a dependency.
20            export wasi:random/insecure@0.2.0;
21        }
22
23        interface units {
24            use wasi:clocks/monotonic-clock@0.2.0.{duration};
25
26            /// Renders the number of bytes as a human readable string.
27            bytes-to-string: func(bytes: u64) -> string;
28
29            /// Renders the provided duration as a human readable string.
30            duration-to-string: func(dur: duration) -> string;
31        }
32    "#,
33
34    // provided here to get the export macro rendered in documentation, not
35    // required for external use.
36    pub_export_macro: true,
37
38    // provided to specify the path to `wasi:*` dependencies referenced above.
39    path: "wasi-cli@0.2.0.wasm",
40
41    // specify that these interface dependencies should be generated as well.
42    with: {
43        "wasi:random/insecure@0.2.0": generate,
44        "wasi:clocks/monotonic-clock@0.2.0": generate,
45        "wasi:io/poll@0.2.0": generate
46    }
47});