dusk_wasmtime/runtime/component/
mod.rs

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#![cfg_attr(docsrs, doc(cfg(feature = "component-model")))]
101// rustdoc appears to lie about a warning above, so squelch it for now.
102#![allow(rustdoc::redundant_explicit_links)]
103
104mod component;
105mod func;
106mod instance;
107mod linker;
108mod matching;
109mod resource_table;
110mod resources;
111mod storage;
112mod store;
113pub mod types;
114mod values;
115pub use self::component::Component;
116pub use self::func::{
117    ComponentNamedList, ComponentType, Func, Lift, Lower, TypedFunc, WasmList, WasmStr,
118};
119pub use self::instance::{ExportInstance, Exports, Instance, InstancePre};
120pub use self::linker::{Linker, LinkerInstance};
121pub use self::resource_table::{ResourceTable, ResourceTableError};
122pub use self::resources::{Resource, ResourceAny};
123pub use self::types::{ResourceType, Type};
124pub use self::values::Val;
125
126pub(crate) use self::resources::HostResourceData;
127
128// These items are expected to be used by an eventual
129// `#[derive(ComponentType)]`, they are not part of Wasmtime's API stability
130// guarantees
131#[doc(hidden)]
132pub mod __internal {
133    pub use super::func::{
134        bad_type_info, format_flags, lower_payload, typecheck_enum, typecheck_flags,
135        typecheck_record, typecheck_variant, ComponentVariant, LiftContext, LowerContext,
136        MaybeUninitExt, Options,
137    };
138    pub use super::matching::InstanceType;
139    pub use crate::map_maybe_uninit;
140    pub use crate::store::StoreOpaque;
141    pub use anyhow;
142    #[cfg(feature = "async")]
143    pub use async_trait::async_trait;
144    pub use wasmtime_environ;
145    pub use wasmtime_environ::component::{CanonicalAbiInfo, ComponentTypes, InterfaceType};
146}
147
148pub(crate) use self::store::ComponentStoreData;
149
150/// Generate bindings for a [WIT world].
151///
152/// [WIT world]: https://component-model.bytecodealliance.org/design/worlds.html
153/// [WIT package]: https://component-model.bytecodealliance.org/design/packages.html
154///
155/// This macro ingests a [WIT world] and will generate all the necessary
156/// bindings for instantiating components that ascribe to the `world`. This
157/// provides a higher-level representation of working with a component than the
158/// raw [`Instance`] type which must be manually-type-checked and manually have
159/// its imports provided via the [`Linker`] type.
160///
161/// The most basic usage of this macro is:
162///
163/// ```rust,ignore
164/// wasmtime::component::bindgen!();
165/// ```
166///
167/// This will parse your projects [WIT package] in a `wit` directory adjacent to
168/// your crate's `Cargo.toml`. All of the `*.wit` files in that directory are
169/// parsed and then the single `world` found will be used for bindings.
170///
171/// For example if your project contained:
172///
173/// ```text,ignore
174/// // wit/my-component.wit
175///
176/// package my:project;
177///
178/// world hello-world {
179///     import name: func() -> string;
180///     export greet: func();
181/// }
182/// ```
183///
184/// Then you can interact with the generated bindings like so:
185///
186/// ```rust
187/// use wasmtime::component::*;
188/// use wasmtime::{Config, Engine, Store};
189///
190/// # const _: () = { macro_rules! bindgen { () => () }
191/// bindgen!();
192/// # };
193/// # bindgen!({
194/// #   inline: r#"
195/// #       package my:project;
196/// #       world hello-world {
197/// #           import name: func() -> string;
198/// #           export greet: func();
199/// #       }
200/// #   "#,
201/// # });
202///
203/// struct MyState {
204///     name: String,
205/// }
206///
207/// // Imports into the world, like the `name` import for this world, are
208/// // satisfied through traits.
209/// impl HelloWorldImports for MyState {
210///     // Note the `Result` return value here where `Ok` is returned back to
211///     // the component and `Err` will raise a trap.
212///     fn name(&mut self) -> wasmtime::Result<String> {
213///         Ok(self.name.clone())
214///     }
215/// }
216///
217/// fn main() -> wasmtime::Result<()> {
218/// #   if true { return Ok(()) }
219///     // Configure an `Engine` and compile the `Component` that is being run for
220///     // the application.
221///     let mut config = Config::new();
222///     config.wasm_component_model(true);
223///     let engine = Engine::new(&config)?;
224///     let component = Component::from_file(&engine, "./your-component.wasm")?;
225///
226///     // Instantiation of bindings always happens through a `Linker`.
227///     // Configuration of the linker is done through a generated `add_to_linker`
228///     // method on the bindings structure.
229///     //
230///     // Note that the closure provided here is a projection from `T` in
231///     // `Store<T>` to `&mut U` where `U` implements the `HelloWorldImports`
232///     // trait. In this case the `T`, `MyState`, is stored directly in the
233///     // structure so no projection is necessary here.
234///     let mut linker = Linker::new(&engine);
235///     HelloWorld::add_to_linker(&mut linker, |state: &mut MyState| state)?;
236///
237///     // As with the core wasm API of Wasmtime instantiation occurs within a
238///     // `Store`. The bindings structure contains an `instantiate` method which
239///     // takes the store, component, and linker. This returns the `bindings`
240///     // structure which is an instance of `HelloWorld` and supports typed access
241///     // to the exports of the component.
242///     let mut store = Store::new(
243///         &engine,
244///         MyState {
245///             name: "me".to_string(),
246///         },
247///     );
248///     let (bindings, _) = HelloWorld::instantiate(&mut store, &component, &linker)?;
249///
250///     // Here our `greet` function doesn't take any parameters for the component,
251///     // but in the Wasmtime embedding API the first argument is always a `Store`.
252///     bindings.call_greet(&mut store)?;
253///     Ok(())
254/// }
255/// ```
256///
257/// The function signatures within generated traits and on generated exports
258/// match the component-model signatures as specified in the WIT `world` item.
259/// Note that WIT also has support for importing and exports interfaces within
260/// worlds, which can be bound here as well:
261///
262/// For example this WIT input
263///
264/// ```text,ignore
265/// // wit/my-component.wit
266///
267/// package my:project;
268///
269/// interface host {
270///     gen-random-integer: func() -> u32;
271///     sha256: func(bytes: list<u8>) -> string;
272/// }
273///
274/// world hello-world {
275///     import host;
276///
277///     export demo: interface {
278///         run: func();
279///     }
280/// }
281/// ```
282///
283/// Then you can interact with the generated bindings like so:
284///
285/// ```rust
286/// use wasmtime::component::*;
287/// use wasmtime::{Config, Engine, Store};
288/// use my::project::host::Host;
289///
290/// # const _: () = { macro_rules! bindgen { () => () }
291/// bindgen!();
292/// # };
293/// # bindgen!({
294/// #   inline: r#"
295/// # package my:project;
296/// #
297/// # interface host {
298/// #     gen-random-integer: func() -> u32;
299/// #     sha256: func(bytes: list<u8>) -> string;
300/// # }
301/// #
302/// # world hello-world {
303/// #     import host;
304/// #
305/// #     export demo: interface {
306/// #         run: func();
307/// #     }
308/// # }
309/// #   "#,
310/// # });
311///
312/// struct MyState {
313///     // ...
314/// }
315///
316/// // Note that the trait here is per-interface and within a submodule now.
317/// impl Host for MyState {
318///     fn gen_random_integer(&mut self) -> wasmtime::Result<u32> {
319/// #       panic!();
320/// #       #[cfg(FALSE)]
321///         Ok(rand::thread_rng().gen())
322///     }
323///
324///     fn sha256(&mut self, bytes: Vec<u8>) -> wasmtime::Result<String> {
325///         // ...
326/// #       panic!()
327///     }
328/// }
329///
330/// fn main() -> wasmtime::Result<()> {
331/// #   if true { return Ok(()) }
332///     let mut config = Config::new();
333///     config.wasm_component_model(true);
334///     let engine = Engine::new(&config)?;
335///     let component = Component::from_file(&engine, "./your-component.wasm")?;
336///
337///     let mut linker = Linker::new(&engine);
338///     HelloWorld::add_to_linker(&mut linker, |state: &mut MyState| state)?;
339///
340///     let mut store = Store::new(
341///         &engine,
342///         MyState { /* ... */ },
343///     );
344///     let (bindings, _) = HelloWorld::instantiate(&mut store, &component, &linker)?;
345///
346///     // Note that the `demo` method returns a `&Demo` through which we can
347///     // run the methods on that interface.
348///     bindings.demo().call_run(&mut store)?;
349///     Ok(())
350/// }
351/// ```
352///
353/// The generated bindings can additionally be explored more fully with `cargo
354/// doc` to see what types and traits and such are generated.
355///
356/// # Syntax
357///
358/// This procedural macro accepts a few different syntaxes. The primary purpose
359/// of this macro is to locate a WIT package, parse it, and then extract a
360/// `world` from the parsed package. There are then codegen-specific options to
361/// the bindings themselves which can additionally be specified.
362///
363/// Usage of this macro looks like:
364///
365/// ```rust,ignore
366/// // Parse the `wit/` folder adjacent to this crate's `Cargo.toml` and look
367/// // for a single `world` in it. There must be exactly one for this to
368/// // succeed.
369/// bindgen!();
370///
371/// // Parse the `wit/` folder adjacent to this crate's `Cargo.toml` and look
372/// // for the world `foo` contained in it.
373/// bindgen!("foo");
374///
375/// // Parse the folder `other/wit/folder` adjacent to `Cargo.toml`.
376/// bindgen!(in "other/wit/folder");
377/// bindgen!("foo" in "other/wit/folder");
378///
379/// // Parse the file `foo.wit` as a single-file WIT package with no
380/// // dependencies.
381/// bindgen!("foo" in "foo.wit");
382/// ```
383///
384/// A more configured version of invoking this macro looks like:
385///
386/// ```rust,ignore
387/// bindgen!({
388///     world: "foo", // not needed if `path` has one `world`
389///
390///     // same as in `bindgen!(in "other/wit/folder")
391///     path: "other/wit/folder",
392///
393///     // Instead of `path` the WIT document can be provided inline if
394///     // desired.
395///     inline: "
396///         package my:inline;
397///
398///         world foo {
399///             // ...
400///         }
401///     ",
402///
403///     // Add calls to `tracing::span!` before each import or export is called
404///     // to log arguments and return values.
405///     //
406///     // This option defaults to `false`.
407///     tracing: true,
408///
409///     // Imports will be async functions through #[async_trait] and exports
410///     // are also invoked as async functions. Requires `Config::async_support`
411///     // to be `true`.
412///     //
413///     // Note that this is only async for the host as the guest will still
414///     // appear as if it's invoking blocking functions.
415///     //
416///     // This option defaults to `false`.
417///     async: true,
418///
419///     // Alternative mode of async configuration where this still implies
420///     // async instantiation happens, for example, but more control is
421///     // provided over which imports are async and which aren't.
422///     //
423///     // Note that in this mode all exports are still async.
424///     async: {
425///         // All imports are async except for functions with these names
426///         except_imports: ["foo", "bar"],
427///
428///         // All imports are synchronous except for functions with these names
429///         //
430///         // Note that this key cannot be specified with `except_imports`,
431///         // only one or the other is accepted.
432///         only_imports: ["foo", "bar"],
433///     },
434///
435///     // This can be used to translate WIT return values of the form
436///     // `result<T, error-type>` into `Result<T, RustErrorType>` in Rust.
437///     // Users must define `RustErrorType` and the `Host` trait for the
438///     // interface which defines `error-type` will have a method
439///     // called `convert_error_type` which converts `RustErrorType`
440///     // into `wasmtime::Result<ErrorType>`. This conversion can either
441///     // return the raw WIT error (`ErrorType` here) or a trap.
442///     //
443///     // By default this option is not specified.
444///     trappable_error_type: {
445///         "wasi:io/streams/stream-error" => RustErrorType,
446///     },
447///
448///     // All generated bindgen types are "owned" meaning types like `String`
449///     // are used instead of `&str`, for example. This is the default and
450///     // ensures that the same type used in both imports and exports uses the
451///     // same generated type.
452///     ownership: Owning,
453///
454///     // Alternative to `Owning` above where borrowed types attempt to be used
455///     // instead. The `duplicate_if_necessary` configures whether duplicate
456///     // Rust types will be generated for the same WIT type if necessary, for
457///     // example when a type is used both as an import and an export.
458///     ownership: Borrowing {
459///         duplicate_if_necessary: true
460///     },
461///
462///     // Restrict the code generated to what's needed for the interface
463///     // imports in the inlined WIT document fragment.
464///     interfaces: "
465///         import wasi:cli/command;
466///     ",
467///
468///     // Remap imported interfaces or resources to types defined in Rust
469///     // elsewhere. Using this option will prevent any code from being
470///     // generated for interfaces mentioned here. Resources named here will
471///     // not have a type generated to represent the resource.
472///     //
473///     // Interfaces mapped with this option should be previously generated
474///     // with an invocation of this macro. Resources need to be mapped to a
475///     // Rust type name.
476///     with: {
477///         // This can be used to indicate that entire interfaces have
478///         // bindings generated elsewhere with a path pointing to the
479///         // bindinges-generated module.
480///         "wasi:random/random": wasmtime_wasi::bindings::random::random,
481///
482///         // Similarly entire packages can also be specified.
483///         "wasi:cli": wasmtime_wasi::bindings::cli,
484///
485///         // Or, if applicable, entire namespaces can additionally be mapped.
486///         "wasi": wasmtime_wasi::bindings,
487///
488///         // Versions are supported if multiple versions are in play:
489///         "wasi:http/types@0.2.0": wasmtime_wasi_http::bindings::http::types,
490///         "wasi:http@0.2.0": wasmtime_wasi_http::bindings::http,
491///
492///         // The `with` key can also be used to specify the `T` used in
493///         // import bindings of `Resource<T>`. This can be done to configure
494///         // which typed resource shows up in generated bindings and can be
495///         // useful when working with the typed methods of `ResourceTable`.
496///         "wasi:filesystem/types/descriptor": MyDescriptorType,
497///     },
498/// });
499/// ```
500pub use wasmtime_component_macro::bindgen;
501
502/// Derive macro to generate implementations of the [`ComponentType`] trait.
503///
504/// This derive macro can be applied to `struct` and `enum` definitions and is
505/// used to bind either a `record`, `enum`, or `variant` in the component model.
506///
507/// Note you might be looking for [`bindgen!`] rather than this macro as that
508/// will generate the entire type for you rather than just a trait
509/// implementation.
510///
511/// This macro supports a `#[component]` attribute which is used to customize
512/// how the type is bound to the component model. A top-level `#[component]`
513/// attribute is required to specify either `record`, `enum`, or `variant`.
514///
515/// ## Records
516///
517/// `record`s in the component model correspond to `struct`s in Rust. An example
518/// is:
519///
520/// ```rust
521/// use wasmtime::component::ComponentType;
522///
523/// #[derive(ComponentType)]
524/// #[component(record)]
525/// struct Color {
526///     r: u8,
527///     g: u8,
528///     b: u8,
529/// }
530/// ```
531///
532/// which corresponds to the WIT type:
533///
534/// ```wit
535/// record color {
536///     r: u8,
537///     g: u8,
538///     b: u8,
539/// }
540/// ```
541///
542/// Note that the name `Color` here does not need to match the name in WIT.
543/// That's purely used as a name in Rust of what to refer to. The field names
544/// must match that in WIT, however. Field names can be customized with the
545/// `#[component]` attribute though.
546///
547/// ```rust
548/// use wasmtime::component::ComponentType;
549///
550/// #[derive(ComponentType)]
551/// #[component(record)]
552/// struct VerboseColor {
553///     #[component(name = "r")]
554///     red: u8,
555///     #[component(name = "g")]
556///     green: u8,
557///     #[component(name = "b")]
558///     blue: u8,
559/// }
560/// ```
561///
562/// Also note that field ordering is significant at this time and must match
563/// WIT.
564///
565/// ## Variants
566///
567/// `variant`s in the component model correspond to a subset of shapes of a Rust
568/// `enum`. Variants in the component model have a single optional payload type
569/// which means that not all Rust `enum`s correspond to component model
570/// `variant`s. An example variant is:
571///
572/// ```rust
573/// use wasmtime::component::ComponentType;
574///
575/// #[derive(ComponentType)]
576/// #[component(variant)]
577/// enum Filter {
578///     #[component(name = "none")]
579///     None,
580///     #[component(name = "all")]
581///     All,
582///     #[component(name = "some")]
583///     Some(Vec<String>),
584/// }
585/// ```
586///
587/// which corresponds to the WIT type:
588///
589/// ```wit
590/// variant filter {
591///     none,
592///     all,
593///     some(list<string>),
594/// }
595/// ```
596///
597/// The `variant` style of derive allows an optional payload on Rust `enum`
598/// variants but it must be a single unnamed field. Variants of the form `Foo(T,
599/// U)` or `Foo { name: T }` are not supported at this time.
600///
601/// Note that the order of variants in Rust must match the order of variants in
602/// WIT. Additionally it's likely that `#[component(name = "...")]` is required
603/// on all Rust `enum` variants because the name currently defaults to the Rust
604/// name which is typically UpperCamelCase whereas WIT uses kebab-case.
605///
606/// ## Enums
607///
608/// `enum`s in the component model correspond to C-like `enum`s in Rust. Note
609/// that a component model `enum` does not allow any payloads so the Rust `enum`
610/// must additionally have no payloads.
611///
612/// ```rust
613/// use wasmtime::component::ComponentType;
614///
615/// #[derive(ComponentType)]
616/// #[component(enum)]
617/// enum Setting {
618///     #[component(name = "yes")]
619///     Yes,
620///     #[component(name = "no")]
621///     No,
622///     #[component(name = "auto")]
623///     Auto,
624/// }
625/// ```
626///
627/// which corresponds to the WIT type:
628///
629/// ```wit
630/// enum setting {
631///     yes,
632///     no,
633///     auto,
634/// }
635/// ```
636///
637/// Note that the order of variants in Rust must match the order of variants in
638/// WIT. Additionally it's likely that `#[component(name = "...")]` is required
639/// on all Rust `enum` variants because the name currently defaults to the Rust
640/// name which is typically UpperCamelCase whereas WIT uses kebab-case.
641pub use wasmtime_component_macro::ComponentType;
642
643/// A derive macro for generating implementations of the [`Lift`] trait.
644///
645/// This macro will likely be applied in conjunction with the
646/// [`#[derive(ComponentType)]`](macro@ComponentType) macro along the lines
647/// of `#[derive(ComponentType, Lift)]`. This trait enables reading values from
648/// WebAssembly.
649///
650/// Note you might be looking for [`bindgen!`] rather than this macro as that
651/// will generate the entire type for you rather than just a trait
652/// implementation.
653///
654/// At this time this derive macro has no configuration.
655///
656/// ## Examples
657///
658/// ```rust
659/// use wasmtime::component::{ComponentType, Lift};
660///
661/// #[derive(ComponentType, Lift)]
662/// #[component(record)]
663/// struct Color {
664///     r: u8,
665///     g: u8,
666///     b: u8,
667/// }
668/// ```
669pub use wasmtime_component_macro::Lift;
670
671/// A derive macro for generating implementations of the [`Lower`] trait.
672///
673/// This macro will likely be applied in conjunction with the
674/// [`#[derive(ComponentType)]`](macro@ComponentType) macro along the lines
675/// of `#[derive(ComponentType, Lower)]`. This trait enables passing values to
676/// WebAssembly.
677///
678/// Note you might be looking for [`bindgen!`] rather than this macro as that
679/// will generate the entire type for you rather than just a trait
680/// implementation.
681///
682/// At this time this derive macro has no configuration.
683///
684/// ## Examples
685///
686/// ```rust
687/// use wasmtime::component::{ComponentType, Lower};
688///
689/// #[derive(ComponentType, Lower)]
690/// #[component(record)]
691/// struct Color {
692///     r: u8,
693///     g: u8,
694///     b: u8,
695/// }
696/// ```
697pub use wasmtime_component_macro::Lower;
698
699/// A macro to generate a Rust type corresponding to WIT `flags`
700///
701/// This macro generates a type that implements the [`ComponentType`], [`Lift`],
702/// and [`Lower`] traits. The generated Rust type corresponds to the `flags`
703/// type in WIT.
704///
705/// Example usage of this looks like:
706///
707/// ```rust
708/// use wasmtime::component::flags;
709///
710/// flags! {
711///     Permissions {
712///         #[component(name = "read")]
713///         const READ;
714///         #[component(name = "write")]
715///         const WRITE;
716///         #[component(name = "execute")]
717///         const EXECUTE;
718///     }
719/// }
720///
721/// fn validate_permissions(permissions: &mut Permissions) {
722///     if permissions.contains(Permissions::EXECUTE | Permissions::WRITE) {
723///         panic!("cannot enable both writable and executable at the same time");
724///     }
725///
726///     if permissions.contains(Permissions::READ) {
727///         panic!("permissions must at least contain read");
728///     }
729/// }
730/// ```
731///
732/// which corresponds to the WIT type:
733///
734/// ```wit
735/// flags permissions {
736///     read,
737///     write,
738///     execute,
739/// }
740/// ```
741///
742/// This generates a structure which is similar to/inspired by the [`bitflags`
743/// crate](https://crates.io/crates/bitflags). The `Permissions` structure
744/// generated implements the [`PartialEq`], [`Eq`], [`Debug`], [`BitOr`],
745/// [`BitOrAssign`], [`BitAnd`], [`BitAndAssign`], [`BitXor`], [`BitXorAssign`],
746/// and [`Not`] traits - in addition to the Wasmtime-specific component ones
747/// [`ComponentType`], [`Lift`], and [`Lower`].
748///
749/// [`BitOr`]: std::ops::BitOr
750/// [`BitOrAssign`]: std::ops::BitOrAssign
751/// [`BitAnd`]: std::ops::BitAnd
752/// [`BitAndAssign`]: std::ops::BitAndAssign
753/// [`BitXor`]: std::ops::BitXor
754/// [`BitXorAssign`]: std::ops::BitXorAssign
755/// [`Not`]: std::ops::Not
756pub use wasmtime_component_macro::flags;