Wasmtime
component/types/func.hh
Go to the documentation of this file.
1
5#ifndef WASMTIME_COMPONENT_TYPES_FUNC_HH
6#define WASMTIME_COMPONENT_TYPES_FUNC_HH
7
8#include <wasmtime/conf.h>
9
10#ifdef WASMTIME_FEATURE_COMPONENT_MODEL
11
14
15namespace wasmtime {
16namespace component {
17
21class FuncType {
22 WASMTIME_CLONE_WRAPPER(FuncType, wasmtime_component_func_type);
23
25 size_t param_count() const {
27 }
28
30 bool async() const { return wasmtime_component_func_type_async(ptr.get()); }
31
33 std::optional<std::pair<std::string_view, ValType>>
34 param_nth(size_t nth) const {
35 const char *name_ptr = nullptr;
36 size_t name_len = 0;
38 if (wasmtime_component_func_type_param_nth(ptr.get(), nth, &name_ptr,
39 &name_len, &type_ret)) {
40 return std::make_pair(std::string_view(name_ptr, name_len),
41 ValType(std::move(type_ret)));
42 }
43 return std::nullopt;
44 }
45
47 std::optional<ValType> result() const {
49 if (wasmtime_component_func_type_result(ptr.get(), &type_ret)) {
50 return ValType(std::move(type_ret));
51 }
52 return std::nullopt;
53 }
54};
55
56} // namespace component
57} // namespace wasmtime
58
59#endif // WASMTIME_FEATURE_COMPONENT_MODEL
60
61#endif // WASMTIME_COMPONENT_TYPES_FUNC_HH
Type information about a component function.
Definition: component/types/func.hh:21
Represents a component value type.
Definition: component/types/val.hh:184
WASM_API_EXTERN wasmtime_component_func_type_t * wasmtime_component_func_type(const wasmtime_component_func_t *func, wasmtime_context_t *context)
Returns the type of this function.
WASM_API_EXTERN bool wasmtime_component_func_type_result(const wasmtime_component_func_type_t *ty, wasmtime_component_valtype_t *type_ret)
Returns the result, if any, of this component function type.
WASM_API_EXTERN size_t wasmtime_component_func_type_param_count(const wasmtime_component_func_type_t *ty)
Returns the number of parameters of a component function type.
WASM_API_EXTERN bool wasmtime_component_func_type_param_nth(const wasmtime_component_func_type_t *ty, size_t nth, const char **name_ret, size_t *name_len_ret, wasmtime_component_valtype_t *type_ret)
Retrieves the nth parameter.
WASM_API_EXTERN bool wasmtime_component_func_type_async(const wasmtime_component_func_type_t *ty)
Returns whether this is an async function.
Build-time defines for how the C API was built.
Represents a single value type in the component model.
Definition: component/types/val.h:463