1 //! # Embedding API for the Component Model
2 //!
3 //! This module contains the embedding API for the [Component Model] in
4 //! Wasmtime. This module requires the `component-model` feature to be enabled,
5 //! which is enabled by default. The embedding API here is mirrored after the
6 //! core wasm embedding API at the crate root and is intended to have the same
7 //! look-and-feel while handling concepts of the component model.
8 //!
9 //! [Component Model]: https://component-model.bytecodealliance.org
10 //!
11 //! The component model is a broad topic which can't be explained here fully, so
12 //! it's recommended to read over individual items' documentation to see more
13 //! about the capabilities of the embedding API. At a high-level, however,
14 //! perhaps the most interesting items in this module are:
15 //!
16 //! * [`Component`] - a compiled component ready to be instantiated. Similar to
17 //!   a [`Module`](crate::Module) for core wasm.
18 //!
19 //! * [`Linker`] - a component-style location for defining host functions. This
20 //!   is not the same as [`wasmtime::Linker`](crate::Linker) for core wasm
21 //!   modules.
22 //!
23 //! * [`bindgen!`] - a macro to generate Rust bindings for a [WIT] [world]. This
24 //!   maps all WIT types into Rust automatically and generates traits for
25 //!   embedders to implement.
26 //!
27 //! [WIT]: https://component-model.bytecodealliance.org/design/wit.html
28 //! [world]: https://component-model.bytecodealliance.org/design/worlds.html
29 //!
30 //! Embedders of the component model will typically start by defining their API
31 //! in [WIT]. This describes what will be available to guests and what needs to
32 //! be provided to the embedder by the guest. This [`world`][world] that was
33 //! created is then fed into [`bindgen!`] to generate types and traits for the
34 //! embedder to use. The embedder then implements these traits, adds
35 //! functionality via the generated `add_to_linker` method (see [`bindgen!`] for
36 //! more info), and then instantiates/executes a component.
37 //!
38 //! It's recommended to read over the [documentation for the Component
39 //! Model][Component Model] to get an overview about how to build components
40 //! from various languages.
41 //!
42 //! ## Example Usage
43 //!
44 //! Imagine you have the following WIT package definition in a file called world.wit
45 //! along with a component (my_component.wasm) that targets `my-world`:
46 //!
47 //! ```text,ignore
48 //! package component:my-package;
49 //!
50 //! world my-world {
51 //!     import name: func() -> string;
52 //!     export greet: func() -> string;
53 //! }
54 //! ```
55 //!
56 //! You can instantiate and call the component like so:
57 //!
58 //! ```
59 //! fn main() -> wasmtime::Result<()> {
60 //!     #   if true { return Ok(()) }
61 //!     // Instantiate the engine and store
62 //!     let engine = wasmtime::Engine::default();
63 //!     let mut store = wasmtime::Store::new(&engine, ());
64 //!
65 //!     // Load the component from disk
66 //!     let bytes = std::fs::read("my_component.wasm")?;
67 //!     let component = wasmtime::component::Component::new(&engine, bytes)?;
68 //!
69 //!     // Configure the linker
70 //!     let mut linker = wasmtime::component::Linker::new(&engine);
71 //!     // The component expects one import `name` that
72 //!     // takes no params and returns a string
73 //!     linker
74 //!         .root()
75 //!         .func_wrap("name", |_store, _params: ()| {
76 //!             Ok((String::from("Alice"),))
77 //!         })?;
78 //!
79 //!     // Instantiate the component
80 //!     let instance = linker.instantiate(&mut store, &component)?;
81 //!
82 //!     // Call the `greet` function
83 //!     let func = instance.get_func(&mut store, "greet").expect("greet export not found");
84 //!     let mut result = [wasmtime::component::Val::String("".into())];
85 //!     func.call(&mut store, &[], &mut result)?;
86 //!
87 //!     // This should print out `Greeting: [String("Hello, Alice!")]`
88 //!     println!("Greeting: {:?}", result);
89 //!
90 //!     Ok(())
91 //! }
92 //! ```
93 //!
94 //! Manually configuring the linker and calling untyped component exports is
95 //! a bit tedious and error prone. The [`bindgen!`] macro can be used to
96 //! generate bindings eliminating much of this boilerplate.
97 //!
98 //! See the docs for [`bindgen!`] for more information on how to use it.
99 
100 // rustdoc appears to lie about a warning above, so squelch it for now.
101 #![allow(rustdoc::redundant_explicit_links)]
102 
103 mod component;
104 mod func;
105 mod instance;
106 mod linker;
107 mod matching;
108 mod resource_table;
109 mod resources;
110 mod storage;
111 mod store;
112 pub mod types;
113 mod values;
114 pub use self::component::{Component, ComponentExportIndex};
115 pub use self::func::{
116     ComponentNamedList, ComponentType, Func, Lift, Lower, TypedFunc, WasmList, WasmStr,
117 };
118 pub use self::instance::{Instance, InstanceExportLookup, InstancePre};
119 pub use self::linker::{Linker, LinkerInstance};
120 pub use self::resource_table::{ResourceTable, ResourceTableError};
121 pub use self::resources::{Resource, ResourceAny};
122 pub use self::types::{ResourceType, Type};
123 pub use self::values::Val;
124 
125 pub(crate) use self::resources::HostResourceData;
126 
127 // These items are expected to be used by an eventual
128 // `#[derive(ComponentType)]`, they are not part of Wasmtime's API stability
129 // guarantees
130 #[doc(hidden)]
131 pub mod __internal {
132     pub use super::func::{
133         bad_type_info, format_flags, lower_payload, typecheck_enum, typecheck_flags,
134         typecheck_record, typecheck_variant, ComponentVariant, LiftContext, LowerContext, Options,
135     };
136     pub use super::matching::InstanceType;
137     pub use crate::map_maybe_uninit;
138     pub use crate::store::StoreOpaque;
139     pub use crate::MaybeUninitExt;
140     pub use alloc::boxed::Box;
141     pub use alloc::string::String;
142     pub use alloc::vec::Vec;
143     pub use anyhow;
144     #[cfg(feature = "async")]
145     pub use async_trait::async_trait;
146     pub use core::mem::transmute;
147     pub use wasmtime_environ;
148     pub use wasmtime_environ::component::{CanonicalAbiInfo, ComponentTypes, InterfaceType};
149 }
150 
151 pub(crate) use self::store::ComponentStoreData;
152 
153 /// Generate bindings for a [WIT world].
154 ///
155 /// [WIT world]: https://component-model.bytecodealliance.org/design/worlds.html
156 /// [WIT package]: https://component-model.bytecodealliance.org/design/packages.html
157 ///
158 /// This macro ingests a [WIT world] and will generate all the necessary
159 /// bindings for instantiating components that ascribe to the `world`. This
160 /// provides a higher-level representation of working with a component than the
161 /// raw [`Instance`] type which must be manually-type-checked and manually have
162 /// its imports provided via the [`Linker`] type.
163 ///
164 /// # Examples
165 ///
166 /// Examples for this macro can be found in the [`bindgen_examples`] module
167 /// documentation. That module has a submodule-per-example which includes the
168 /// source code, with WIT, used to generate the structures along with the
169 /// generated code itself in documentation.
170 ///
171 /// # Debugging and Exploring
172 ///
173 /// If you need to debug the output of `bindgen!` you can try using the
174 /// `WASMTIME_DEBUG_BINDGEN=1` environment variable. This will write the
175 /// generated code to a file on disk so rustc can produce better error messages
176 /// against the actual generated source instead of the macro invocation itself.
177 /// This additionally can enable opening up the generated code in an editor and
178 /// exploring it (through an error message).
179 ///
180 /// The generated bindings can additionally be explored with `cargo doc` to see
181 /// what's generated. It's also recommended to browse the [`bindgen_examples`]
182 /// for example generated structures and example generated code.
183 ///
184 /// # Syntax
185 ///
186 /// This procedural macro accepts a few different syntaxes. The primary purpose
187 /// of this macro is to locate a WIT package, parse it, and then extract a
188 /// `world` from the parsed package. There are then codegen-specific options to
189 /// the bindings themselves which can additionally be specified.
190 ///
191 /// Usage of this macro looks like:
192 ///
193 /// ```rust
194 /// # macro_rules! bindgen { ($($t:tt)*) => () }
195 /// // Parse the `wit/` folder adjacent to this crate's `Cargo.toml` and look
196 /// // for a single `world` in it. There must be exactly one for this to
197 /// // succeed.
198 /// bindgen!();
199 ///
200 /// // Parse the `wit/` folder adjacent to this crate's `Cargo.toml` and look
201 /// // for the world `foo` contained in it.
202 /// bindgen!("foo");
203 ///
204 /// // Parse the folder `other/wit/folder` adjacent to `Cargo.toml`.
205 /// bindgen!(in "other/wit/folder");
206 /// bindgen!("foo" in "other/wit/folder");
207 ///
208 /// // Parse the file `foo.wit` as a single-file WIT package with no
209 /// // dependencies.
210 /// bindgen!("foo" in "foo.wit");
211 ///
212 /// // Specify a suite of options to the bindings generation, documented below
213 /// bindgen!({
214 ///     world: "foo",
215 ///     path: "other/path/to/wit",
216 ///     // ...
217 /// });
218 /// ```
219 ///
220 /// # Options Reference
221 ///
222 /// This is an example listing of all options that this macro supports along
223 /// with documentation for each option and example syntax for each option.
224 ///
225 /// ```rust
226 /// # macro_rules! bindgen { ($($t:tt)*) => () }
227 /// bindgen!({
228 ///     world: "foo", // not needed if `path` has one `world`
229 ///
230 ///     // same as in `bindgen!(in "other/wit/folder")
231 ///     path: "other/wit/folder",
232 ///
233 ///     // Instead of `path` the WIT document can be provided inline if
234 ///     // desired.
235 ///     inline: "
236 ///         package my:inline;
237 ///
238 ///         world foo {
239 ///             // ...
240 ///         }
241 ///     ",
242 ///
243 ///     // Add calls to `tracing::span!` before each import or export is called
244 ///     // to log arguments and return values.
245 ///     //
246 ///     // This option defaults to `false`.
247 ///     tracing: true,
248 ///
249 ///     // Imports will be async functions through #[async_trait] and exports
250 ///     // are also invoked as async functions. Requires `Config::async_support`
251 ///     // to be `true`.
252 ///     //
253 ///     // Note that this is only async for the host as the guest will still
254 ///     // appear as if it's invoking blocking functions.
255 ///     //
256 ///     // This option defaults to `false`.
257 ///     async: true,
258 ///
259 ///     // Alternative mode of async configuration where this still implies
260 ///     // async instantiation happens, for example, but more control is
261 ///     // provided over which imports are async and which aren't.
262 ///     //
263 ///     // Note that in this mode all exports are still async.
264 ///     async: {
265 ///         // All imports are async except for functions with these names
266 ///         except_imports: ["foo", "bar"],
267 ///
268 ///         // All imports are synchronous except for functions with these names
269 ///         //
270 ///         // Note that this key cannot be specified with `except_imports`,
271 ///         // only one or the other is accepted.
272 ///         only_imports: ["foo", "bar"],
273 ///     },
274 ///
275 ///     // This option is used to indicate whether imports can trap.
276 ///     //
277 ///     // Imports that may trap have their return types wrapped in
278 ///     // `wasmtime::Result<T>` where the `Err` variant indicates that a
279 ///     // trap will be raised in the guest.
280 ///     //
281 ///     // By default imports cannot trap and the return value is the return
282 ///     // value from the WIT bindings itself. This value can be set to `true`
283 ///     // to indicate that any import can trap. This value can also be set to
284 ///     // an array-of-strings to indicate that only a set list of imports
285 ///     // can trap.
286 ///     trappable_imports: false,             // no imports can trap (default)
287 ///     // trappable_imports: true,           // all imports can trap
288 ///     // trappable_imports: ["foo", "bar"], // only these can trap
289 ///
290 ///     // This can be used to translate WIT return values of the form
291 ///     // `result<T, error-type>` into `Result<T, RustErrorType>` in Rust.
292 ///     // Users must define `RustErrorType` and the `Host` trait for the
293 ///     // interface which defines `error-type` will have a method
294 ///     // called `convert_error_type` which converts `RustErrorType`
295 ///     // into `wasmtime::Result<ErrorType>`. This conversion can either
296 ///     // return the raw WIT error (`ErrorType` here) or a trap.
297 ///     //
298 ///     // By default this option is not specified. This option only takes
299 ///     // effect when `trappable_imports` is set for some imports.
300 ///     trappable_error_type: {
301 ///         "wasi:io/streams/stream-error" => RustErrorType,
302 ///     },
303 ///
304 ///     // All generated bindgen types are "owned" meaning types like `String`
305 ///     // are used instead of `&str`, for example. This is the default and
306 ///     // ensures that the same type used in both imports and exports uses the
307 ///     // same generated type.
308 ///     ownership: Owning,
309 ///
310 ///     // Alternative to `Owning` above where borrowed types attempt to be used
311 ///     // instead. The `duplicate_if_necessary` configures whether duplicate
312 ///     // Rust types will be generated for the same WIT type if necessary, for
313 ///     // example when a type is used both as an import and an export.
314 ///     ownership: Borrowing {
315 ///         duplicate_if_necessary: true
316 ///     },
317 ///
318 ///     // Restrict the code generated to what's needed for the interface
319 ///     // imports in the inlined WIT document fragment.
320 ///     interfaces: "
321 ///         import wasi:cli/command;
322 ///     ",
323 ///
324 ///     // Remap imported interfaces or resources to types defined in Rust
325 ///     // elsewhere. Using this option will prevent any code from being
326 ///     // generated for interfaces mentioned here. Resources named here will
327 ///     // not have a type generated to represent the resource.
328 ///     //
329 ///     // Interfaces mapped with this option should be previously generated
330 ///     // with an invocation of this macro. Resources need to be mapped to a
331 ///     // Rust type name.
332 ///     with: {
333 ///         // This can be used to indicate that entire interfaces have
334 ///         // bindings generated elsewhere with a path pointing to the
335 ///         // bindinges-generated module.
336 ///         "wasi:random/random": wasmtime_wasi::bindings::random::random,
337 ///
338 ///         // Similarly entire packages can also be specified.
339 ///         "wasi:cli": wasmtime_wasi::bindings::cli,
340 ///
341 ///         // Or, if applicable, entire namespaces can additionally be mapped.
342 ///         "wasi": wasmtime_wasi::bindings,
343 ///
344 ///         // Versions are supported if multiple versions are in play:
345 ///         "wasi:http/types@0.2.0": wasmtime_wasi_http::bindings::http::types,
346 ///         "wasi:[email protected]": wasmtime_wasi_http::bindings::http,
347 ///
348 ///         // The `with` key can also be used to specify the `T` used in
349 ///         // import bindings of `Resource<T>`. This can be done to configure
350 ///         // which typed resource shows up in generated bindings and can be
351 ///         // useful when working with the typed methods of `ResourceTable`.
352 ///         "wasi:filesystem/types/descriptor": MyDescriptorType,
353 ///     },
354 ///
355 ///     // Additional derive attributes to include on generated types (structs or enums).
356 ///     //
357 ///     // These are deduplicated and attached in a deterministic order.
358 ///     additional_derives: [
359 ///         Hash,
360 ///         serde::Deserialize,
361 ///         serde::Serialize,
362 ///     ],
363 ///
364 ///     // A list of WIT "features" to enable when parsing the WIT document that
365 ///     // this bindgen macro matches. WIT features are all disabled by default
366 ///     // and must be opted-in-to if source level features are used.
367 ///     //
368 ///     // This option defaults to an empty array.
369 ///     features: ["foo", "bar", "baz"],
370 ///
371 ///     // An niche configuration option to require that the `T` in `Store<T>`
372 ///     // is always `Send` in the generated bindings. Typically not needed
373 ///     // but if synchronous bindings depend on asynchronous bindings using
374 ///     // the `with` key then this may be required.
375 ///     require_store_data_send: false,
376 ///
377 ///     // If the `wasmtime` crate is depended on at a nonstandard location
378 ///     // or is renamed then this is the path to the root of the `wasmtime`
379 ///     // crate. Much of the generated code needs to refer to `wasmtime` so
380 ///     // this should be used if the `wasmtime` name is not wasmtime itself.
381 ///     //
382 ///     // By default this is `wasmtime`.
383 ///     wasmtime_crate: path::to::wasmtime,
384 ///
385 ///     // This is an in-source alternative to using `WASMTIME_DEBUG_BINDGEN`.
386 ///     //
387 ///     // Note that if this option is specified then the compiler will always
388 ///     // recompile your bindings. Cargo records the start time of when rustc
389 ///     // is spawned by this will write a file during compilation. To Cargo
390 ///     // that looks like a file was modified after `rustc` was spawned,
391 ///     // so Cargo will always think your project is "dirty" and thus always
392 ///     // recompile it. Recompiling will then overwrite the file again,
393 ///     // starting the cycle anew. This is only recommended for debugging.
394 ///     //
395 ///     // This option defaults to false.
396 ///     include_generated_code_from_file: false,
397 /// });
398 /// ```
399 pub use wasmtime_component_macro::bindgen;
400 
401 /// Derive macro to generate implementations of the [`ComponentType`] trait.
402 ///
403 /// This derive macro can be applied to `struct` and `enum` definitions and is
404 /// used to bind either a `record`, `enum`, or `variant` in the component model.
405 ///
406 /// Note you might be looking for [`bindgen!`] rather than this macro as that
407 /// will generate the entire type for you rather than just a trait
408 /// implementation.
409 ///
410 /// This macro supports a `#[component]` attribute which is used to customize
411 /// how the type is bound to the component model. A top-level `#[component]`
412 /// attribute is required to specify either `record`, `enum`, or `variant`.
413 ///
414 /// ## Records
415 ///
416 /// `record`s in the component model correspond to `struct`s in Rust. An example
417 /// is:
418 ///
419 /// ```rust
420 /// use wasmtime::component::ComponentType;
421 ///
422 /// #[derive(ComponentType)]
423 /// #[component(record)]
424 /// struct Color {
425 ///     r: u8,
426 ///     g: u8,
427 ///     b: u8,
428 /// }
429 /// ```
430 ///
431 /// which corresponds to the WIT type:
432 ///
433 /// ```wit
434 /// record color {
435 ///     r: u8,
436 ///     g: u8,
437 ///     b: u8,
438 /// }
439 /// ```
440 ///
441 /// Note that the name `Color` here does not need to match the name in WIT.
442 /// That's purely used as a name in Rust of what to refer to. The field names
443 /// must match that in WIT, however. Field names can be customized with the
444 /// `#[component]` attribute though.
445 ///
446 /// ```rust
447 /// use wasmtime::component::ComponentType;
448 ///
449 /// #[derive(ComponentType)]
450 /// #[component(record)]
451 /// struct VerboseColor {
452 ///     #[component(name = "r")]
453 ///     red: u8,
454 ///     #[component(name = "g")]
455 ///     green: u8,
456 ///     #[component(name = "b")]
457 ///     blue: u8,
458 /// }
459 /// ```
460 ///
461 /// Also note that field ordering is significant at this time and must match
462 /// WIT.
463 ///
464 /// ## Variants
465 ///
466 /// `variant`s in the component model correspond to a subset of shapes of a Rust
467 /// `enum`. Variants in the component model have a single optional payload type
468 /// which means that not all Rust `enum`s correspond to component model
469 /// `variant`s. An example variant is:
470 ///
471 /// ```rust
472 /// use wasmtime::component::ComponentType;
473 ///
474 /// #[derive(ComponentType)]
475 /// #[component(variant)]
476 /// enum Filter {
477 ///     #[component(name = "none")]
478 ///     None,
479 ///     #[component(name = "all")]
480 ///     All,
481 ///     #[component(name = "some")]
482 ///     Some(Vec<String>),
483 /// }
484 /// ```
485 ///
486 /// which corresponds to the WIT type:
487 ///
488 /// ```wit
489 /// variant filter {
490 ///     none,
491 ///     all,
492 ///     some(list<string>),
493 /// }
494 /// ```
495 ///
496 /// The `variant` style of derive allows an optional payload on Rust `enum`
497 /// variants but it must be a single unnamed field. Variants of the form `Foo(T,
498 /// U)` or `Foo { name: T }` are not supported at this time.
499 ///
500 /// Note that the order of variants in Rust must match the order of variants in
501 /// WIT. Additionally it's likely that `#[component(name = "...")]` is required
502 /// on all Rust `enum` variants because the name currently defaults to the Rust
503 /// name which is typically UpperCamelCase whereas WIT uses kebab-case.
504 ///
505 /// ## Enums
506 ///
507 /// `enum`s in the component model correspond to C-like `enum`s in Rust. Note
508 /// that a component model `enum` does not allow any payloads so the Rust `enum`
509 /// must additionally have no payloads.
510 ///
511 /// ```rust
512 /// use wasmtime::component::ComponentType;
513 ///
514 /// #[derive(ComponentType)]
515 /// #[component(enum)]
516 /// #[repr(u8)]
517 /// enum Setting {
518 ///     #[component(name = "yes")]
519 ///     Yes,
520 ///     #[component(name = "no")]
521 ///     No,
522 ///     #[component(name = "auto")]
523 ///     Auto,
524 /// }
525 /// ```
526 ///
527 /// which corresponds to the WIT type:
528 ///
529 /// ```wit
530 /// enum setting {
531 ///     yes,
532 ///     no,
533 ///     auto,
534 /// }
535 /// ```
536 ///
537 /// Note that the order of variants in Rust must match the order of variants in
538 /// WIT. Additionally it's likely that `#[component(name = "...")]` is required
539 /// on all Rust `enum` variants because the name currently defaults to the Rust
540 /// name which is typically UpperCamelCase whereas WIT uses kebab-case.
541 pub use wasmtime_component_macro::ComponentType;
542 
543 /// A derive macro for generating implementations of the [`Lift`] trait.
544 ///
545 /// This macro will likely be applied in conjunction with the
546 /// [`#[derive(ComponentType)]`](macro@ComponentType) macro along the lines
547 /// of `#[derive(ComponentType, Lift)]`. This trait enables reading values from
548 /// WebAssembly.
549 ///
550 /// Note you might be looking for [`bindgen!`] rather than this macro as that
551 /// will generate the entire type for you rather than just a trait
552 /// implementation.
553 ///
554 /// At this time this derive macro has no configuration.
555 ///
556 /// ## Examples
557 ///
558 /// ```rust
559 /// use wasmtime::component::{ComponentType, Lift};
560 ///
561 /// #[derive(ComponentType, Lift)]
562 /// #[component(record)]
563 /// struct Color {
564 ///     r: u8,
565 ///     g: u8,
566 ///     b: u8,
567 /// }
568 /// ```
569 pub use wasmtime_component_macro::Lift;
570 
571 /// A derive macro for generating implementations of the [`Lower`] trait.
572 ///
573 /// This macro will likely be applied in conjunction with the
574 /// [`#[derive(ComponentType)]`](macro@ComponentType) macro along the lines
575 /// of `#[derive(ComponentType, Lower)]`. This trait enables passing values to
576 /// WebAssembly.
577 ///
578 /// Note you might be looking for [`bindgen!`] rather than this macro as that
579 /// will generate the entire type for you rather than just a trait
580 /// implementation.
581 ///
582 /// At this time this derive macro has no configuration.
583 ///
584 /// ## Examples
585 ///
586 /// ```rust
587 /// use wasmtime::component::{ComponentType, Lower};
588 ///
589 /// #[derive(ComponentType, Lower)]
590 /// #[component(record)]
591 /// struct Color {
592 ///     r: u8,
593 ///     g: u8,
594 ///     b: u8,
595 /// }
596 /// ```
597 pub use wasmtime_component_macro::Lower;
598 
599 /// A macro to generate a Rust type corresponding to WIT `flags`
600 ///
601 /// This macro generates a type that implements the [`ComponentType`], [`Lift`],
602 /// and [`Lower`] traits. The generated Rust type corresponds to the `flags`
603 /// type in WIT.
604 ///
605 /// Example usage of this looks like:
606 ///
607 /// ```rust
608 /// use wasmtime::component::flags;
609 ///
610 /// flags! {
611 ///     Permissions {
612 ///         #[component(name = "read")]
613 ///         const READ;
614 ///         #[component(name = "write")]
615 ///         const WRITE;
616 ///         #[component(name = "execute")]
617 ///         const EXECUTE;
618 ///     }
619 /// }
620 ///
621 /// fn validate_permissions(permissions: &mut Permissions) {
622 ///     if permissions.contains(Permissions::EXECUTE | Permissions::WRITE) {
623 ///         panic!("cannot enable both writable and executable at the same time");
624 ///     }
625 ///
626 ///     if permissions.contains(Permissions::READ) {
627 ///         panic!("permissions must at least contain read");
628 ///     }
629 /// }
630 /// ```
631 ///
632 /// which corresponds to the WIT type:
633 ///
634 /// ```wit
635 /// flags permissions {
636 ///     read,
637 ///     write,
638 ///     execute,
639 /// }
640 /// ```
641 ///
642 /// This generates a structure which is similar to/inspired by the [`bitflags`
643 /// crate](https://crates.io/crates/bitflags). The `Permissions` structure
644 /// generated implements the [`PartialEq`], [`Eq`], [`Debug`], [`BitOr`],
645 /// [`BitOrAssign`], [`BitAnd`], [`BitAndAssign`], [`BitXor`], [`BitXorAssign`],
646 /// and [`Not`] traits - in addition to the Wasmtime-specific component ones
647 /// [`ComponentType`], [`Lift`], and [`Lower`].
648 ///
649 /// [`BitOr`]: std::ops::BitOr
650 /// [`BitOrAssign`]: std::ops::BitOrAssign
651 /// [`BitAnd`]: std::ops::BitAnd
652 /// [`BitAndAssign`]: std::ops::BitAndAssign
653 /// [`BitXor`]: std::ops::BitXor
654 /// [`BitXorAssign`]: std::ops::BitXorAssign
655 /// [`Not`]: std::ops::Not
656 pub use wasmtime_component_macro::flags;
657 
658 #[cfg(any(docsrs, test, doctest))]
659 pub mod bindgen_examples;
660 
661 // NB: needed for the links in the docs above to work in all `cargo doc`
662 // configurations and avoid errors.
663 #[cfg(not(any(docsrs, test, doctest)))]
664 #[doc(hidden)]
665 pub mod bindgen_examples {}
666