1 bindgen!({ 2 inline: r#" 3 package example:imported-resources; 4 5 interface logging { 6 enum level { 7 debug, 8 info, 9 warn, 10 error, 11 } 12 13 resource logger { 14 constructor(max-level: level); 15 16 get-max-level: func() -> level; 17 set-max-level: func(level: level); 18 19 log: func(level: level, msg: string); 20 } 21 } 22 23 world import-some-resources { 24 import logging; 25 } 26 "#, 27 28 with: { 29 // Specify that our host resource is going to point to the `MyLogger` 30 // which is defined just below this macro. 31 "example:imported-resources/logging.logger": MyLogger, 32 }, 33 34 // Interactions with `ResourceTable` can possibly trap so enable the ability 35 // to return traps from generated functions. 36 imports: { default: trappable }, 37 }); 38 39 /// A sample host-defined type which contains arbitrary host-defined data. 40 /// 41 /// In this case this is relatively simple but there's no restrictions on what 42 /// this type can hold other than that it must be `'static + Send`. 43 pub struct MyLogger { 44 pub max_level: example::imported_resources::logging::Level, 45 } 46