Wasmtime
component/types/instance.hh
Go to the documentation of this file.
1
5#ifndef WASMTIME_COMPONENT_TYPES_INSTANCE_HH
6#define WASMTIME_COMPONENT_TYPES_INSTANCE_HH
7
8#include <wasmtime/conf.h>
9
10#ifdef WASMTIME_FEATURE_COMPONENT_MODEL
11
12#include <memory>
13#include <optional>
14#include <string>
16#include <wasmtime/engine.hh>
17#include <wasmtime/helpers.hh>
18
19namespace wasmtime {
20namespace component {
21
22class ComponentItem;
23
28 WASMTIME_CLONE_WRAPPER(ComponentInstanceType,
29 wasmtime_component_instance_type);
30
32 size_t export_count(const Engine &engine) const {
33 return wasmtime_component_instance_type_export_count(capi(), engine.capi());
34 }
35
37 std::optional<ComponentItem> export_get(const Engine &engine,
38 std::string_view name) const;
39
41 std::optional<std::pair<std::string_view, ComponentItem>>
42 export_nth(const Engine &engine, size_t nth) const;
43};
44
45} // namespace component
46} // namespace wasmtime
47
49
50inline std::optional<wasmtime::component::ComponentItem>
51wasmtime::component::ComponentInstanceType::export_get(
52 const wasmtime::Engine &engine, std::string_view name) const {
55 capi(), engine.capi(), name.data(), name.size(), &item);
56 if (!found) {
57 return std::nullopt;
58 }
59 return wasmtime::component::ComponentItem(std::move(item));
60}
61
62inline std::optional<
63 std::pair<std::string_view, wasmtime::component::ComponentItem>>
64wasmtime::component::ComponentInstanceType::export_nth(
65 const wasmtime::Engine &engine, size_t nth) const {
67 const char *name_data;
68 size_t name_size;
70 capi(), engine.capi(), nth, &name_data, &name_size, &item);
71 if (!found) {
72 return std::nullopt;
73 }
74 return std::make_pair(std::string_view(name_data, name_size),
75 wasmtime::component::ComponentItem(std::move(item)));
76}
77
78#endif // WASMTIME_FEATURE_COMPONENT_MODEL
79
80#endif // WASMTIME_COMPONENT_TYPES_INSTANCE_HH
Global compilation state in Wasmtime.
Definition: engine.hh:22
Represents the type of a component instance.
Definition: component/types/instance.hh:27
Represents a single item in a component's import or export list.
Definition: component/types/component.hh:68
WASM_API_EXTERN bool wasmtime_component_instance_type_export_get(const wasmtime_component_instance_type_t *ty, const wasm_engine_t *engine, const char *name, size_t name_len, struct wasmtime_component_item_t *ret)
Retrieves the export with the specified name.
WASM_API_EXTERN bool wasmtime_component_instance_type_export_nth(const wasmtime_component_instance_type_t *ty, const wasm_engine_t *engine, size_t nth, const char **name_ret, size_t *name_len_ret, struct wasmtime_component_item_t *type_ret)
Retrieves the nth export.
WASM_API_EXTERN size_t wasmtime_component_instance_type_export_count(const wasmtime_component_instance_type_t *ty, const wasm_engine_t *engine)
Returns the number of exports of a component instance type.
Build-time defines for how the C API was built.
Represents a single item in a component's import or export list.
Definition: component/types/component.h:137