Wasmtime
component/types/val.hh
Go to the documentation of this file.
1
5#ifndef WASMTIME_COMPONENT_TYPES_VAL_HH
6#define WASMTIME_COMPONENT_TYPES_VAL_HH
7
8#include <wasmtime/conf.h>
9
10#ifdef WASMTIME_FEATURE_COMPONENT_MODEL
11
12#include <memory>
13#include <optional>
14#include <string_view>
16#include <wasmtime/helpers.hh>
17
18namespace wasmtime {
19namespace component {
20
21class ValType;
22
26class ListType {
27 WASMTIME_CLONE_EQUAL_WRAPPER(ListType, wasmtime_component_list_type);
28
30 ValType element() const;
31};
32
37 WASMTIME_CLONE_EQUAL_WRAPPER(RecordType, wasmtime_component_record_type);
38
40 size_t field_count() const {
42 }
43
45 std::optional<std::pair<std::string_view, ValType>>
46 field_nth(size_t nth) const;
47};
48
52class TupleType {
53 WASMTIME_CLONE_EQUAL_WRAPPER(TupleType, wasmtime_component_tuple_type);
54
56 size_t types_count() const {
58 }
59
61 std::optional<ValType> types_nth(size_t nth) const;
62};
63
68 WASMTIME_CLONE_EQUAL_WRAPPER(VariantType, wasmtime_component_variant_type);
69
71 size_t case_count() const {
73 }
74
76 std::optional<std::pair<std::string_view, std::optional<ValType>>>
77 case_nth(size_t nth) const;
78};
79
83class EnumType {
84 WASMTIME_CLONE_EQUAL_WRAPPER(EnumType, wasmtime_component_enum_type);
85
87 size_t names_count() const {
89 }
90
92 std::optional<std::string_view> names_nth(size_t nth) const {
93 const char *name_ptr = nullptr;
94 size_t name_len = 0;
95 if (wasmtime_component_enum_type_names_nth(ptr.get(), nth, &name_ptr,
96 &name_len)) {
97 return std::string_view(name_ptr, name_len);
98 }
99 return std::nullopt;
100 }
101};
102
107 WASMTIME_CLONE_EQUAL_WRAPPER(OptionType, wasmtime_component_option_type);
108
110 ValType ty() const;
111};
112
117 WASMTIME_CLONE_EQUAL_WRAPPER(ResultType, wasmtime_component_result_type);
118
120 std::optional<ValType> ok() const;
121
123 std::optional<ValType> err() const;
124};
125
130 WASMTIME_CLONE_EQUAL_WRAPPER(FlagsType, wasmtime_component_flags_type);
131
133 size_t names_count() const {
135 }
136
138 std::optional<std::string_view> names_nth(size_t nth) const {
139 const char *name_ptr = nullptr;
140 size_t name_len = 0;
141 if (wasmtime_component_flags_type_names_nth(ptr.get(), nth, &name_ptr,
142 &name_len)) {
143 return std::string_view(name_ptr, name_len);
144 }
145 return std::nullopt;
146 }
147};
148
152 WASMTIME_CLONE_EQUAL_WRAPPER(ResourceType, wasmtime_component_resource_type);
153
154public:
157 explicit ResourceType(uint32_t ty)
159};
160
165 WASMTIME_CLONE_EQUAL_WRAPPER(FutureType, wasmtime_component_future_type);
166
168 std::optional<ValType> ty() const;
169};
170
175 WASMTIME_CLONE_EQUAL_WRAPPER(StreamType, wasmtime_component_stream_type);
176
178 std::optional<ValType> ty() const;
179};
180
184class MapType {
185 WASMTIME_CLONE_EQUAL_WRAPPER(MapType, wasmtime_component_map_type);
186
188 ValType key() const;
189
191 ValType value() const;
192};
193
197class ValType {
199
202 ty.kind = kind;
203 return ValType(std::move(ty));
204 }
205
206public:
209 this->ty = ty;
211 }
212
214 ValType(const ValType &other) {
215 wasmtime_component_valtype_clone(&other.ty, &ty);
216 }
217
219 ValType &operator=(const ValType &other) {
221 wasmtime_component_valtype_clone(&other.ty, &ty);
222 return *this;
223 }
224
226 ValType(ValType &&other) : ty(other.ty) {
228 }
229
233 ty = other.ty;
235 return *this;
236 }
237
239
245 static_assert(sizeof(ValType) == sizeof(wasmtime_component_valtype_t));
246 return reinterpret_cast<const ValType *>(capi);
247 }
248
250 bool operator==(const ValType &other) const {
251 return wasmtime_component_valtype_equal(&ty, &other.ty);
252 }
253
255 bool operator!=(const ValType &other) const { return !(*this == other); }
256
258 static ValType new_bool() {
259 return ValType::new_kind(WASMTIME_COMPONENT_VALTYPE_BOOL);
260 }
261
263 static ValType new_s8() {
264 return ValType::new_kind(WASMTIME_COMPONENT_VALTYPE_S8);
265 }
266
268 static ValType new_s16() {
269 return ValType::new_kind(WASMTIME_COMPONENT_VALTYPE_S16);
270 }
271
273 static ValType new_s32() {
274 return ValType::new_kind(WASMTIME_COMPONENT_VALTYPE_S32);
275 }
276
278 static ValType new_s64() {
279 return ValType::new_kind(WASMTIME_COMPONENT_VALTYPE_S64);
280 }
281
283 static ValType new_u8() {
284 return ValType::new_kind(WASMTIME_COMPONENT_VALTYPE_U8);
285 }
286
288 static ValType new_u16() {
289 return ValType::new_kind(WASMTIME_COMPONENT_VALTYPE_U16);
290 }
291
293 static ValType new_u32() {
294 return ValType::new_kind(WASMTIME_COMPONENT_VALTYPE_U32);
295 }
296
298 static ValType new_u64() {
299 return ValType::new_kind(WASMTIME_COMPONENT_VALTYPE_U64);
300 }
301
303 static ValType new_f32() {
304 return ValType::new_kind(WASMTIME_COMPONENT_VALTYPE_F32);
305 }
306
308 static ValType new_f64() {
309 return ValType::new_kind(WASMTIME_COMPONENT_VALTYPE_F64);
310 }
311
313 static ValType new_char() {
314 return ValType::new_kind(WASMTIME_COMPONENT_VALTYPE_CHAR);
315 }
316
319 return ValType::new_kind(WASMTIME_COMPONENT_VALTYPE_STRING);
320 }
321
325 ty.of.list = list.capi_release();
326 }
327
331 ty.of.record = record.capi_release();
332 }
333
337 ty.of.tuple = tuple.capi_release();
338 }
339
343 ty.of.variant = variant.capi_release();
344 }
345
349 ty.of.enum_ = enum_.capi_release();
350 }
351
355 ty.of.option = option.capi_release();
356 }
357
361 ty.of.result = result.capi_release();
362 }
363
367 ty.of.flags = flags.capi_release();
368 }
369
374 ty.of.own = own.capi_release();
375 return ValType(std::move(ty));
376 }
377
382 ty.of.borrow = borrow.capi_release();
383 return ValType(std::move(ty));
384 }
385
389 ty.of.future = future.capi_release();
390 }
391
395 ty.of.stream = stream.capi_release();
396 }
397
401 ty.of.map = map.capi_release();
402 }
403
406
408 bool is_bool() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_BOOL; }
409
411 bool is_s8() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_S8; }
412
414 bool is_s16() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_S16; }
415
417 bool is_s32() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_S32; }
418
420 bool is_s64() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_S64; }
421
423 bool is_u8() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_U8; }
424
426 bool is_u16() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_U16; }
427
429 bool is_u32() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_U32; }
430
432 bool is_u64() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_U64; }
433
435 bool is_f32() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_F32; }
436
438 bool is_f64() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_F64; }
439
441 bool is_char() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_CHAR; }
442
444 bool is_string() const {
446 }
447
449 bool is_list() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_LIST; }
450
452 bool is_record() const {
454 }
455
457 bool is_tuple() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_TUPLE; }
458
460 bool is_variant() const {
462 }
463
465 bool is_enum() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_ENUM; }
466
468 bool is_option() const {
470 }
471
473 bool is_result() const {
475 }
476
478 bool is_flags() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_FLAGS; }
479
481 bool is_own() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_OWN; }
482
484 bool is_borrow() const {
486 }
487
489 bool is_future() const {
491 }
492
494 bool is_stream() const {
496 }
497
499 bool is_error_context() const {
501 }
502
504 bool is_map() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_MAP; }
505
507 const ListType &list() const {
508 assert(is_list());
509 return *ListType::from_capi(&ty.of.list);
510 }
511
513 const RecordType &record() const {
514 assert(is_record());
515 return *RecordType::from_capi(&ty.of.record);
516 }
517
519 const TupleType &tuple() const {
520 assert(is_tuple());
521 return *TupleType::from_capi(&ty.of.tuple);
522 }
523
525 const VariantType &variant() const {
526 assert(is_variant());
527 return *VariantType::from_capi(&ty.of.variant);
528 }
529
531 const EnumType &enum_() const {
532 assert(is_enum());
533 return *EnumType::from_capi(&ty.of.enum_);
534 }
535
537 const OptionType &option() const {
538 assert(is_option());
539 return *OptionType::from_capi(&ty.of.option);
540 }
541
543 const ResultType &result() const {
544 assert(is_result());
545 return *ResultType::from_capi(&ty.of.result);
546 }
547
549 const FlagsType &flags() const {
550 assert(is_flags());
551 return *FlagsType::from_capi(&ty.of.flags);
552 }
553
555 const ResourceType &own() const {
556 assert(is_own());
557 return *ResourceType::from_capi(&ty.of.own);
558 }
559
561 const ResourceType &borrow() const {
562 assert(is_borrow());
563 return *ResourceType::from_capi(&ty.of.borrow);
564 }
565
567 const FutureType &future() const {
568 assert(is_future());
569 return *FutureType::from_capi(&ty.of.future);
570 }
571
573 const StreamType &stream() const {
574 assert(is_stream());
575 return *StreamType::from_capi(&ty.of.stream);
576 }
577
579 const MapType &map() const {
580 assert(is_map());
581 return *MapType::from_capi(&ty.of.map);
582 }
583
585 const wasmtime_component_valtype_t *capi() const { return &ty; }
588};
589
590inline ValType ListType::element() const {
592 wasmtime_component_list_type_element(ptr.get(), &type_ret);
593 return ValType(std::move(type_ret));
594}
595
596inline std::optional<std::pair<std::string_view, ValType>>
597RecordType::field_nth(size_t nth) const {
598 const char *name_ptr = nullptr;
599 size_t name_len = 0;
601 if (wasmtime_component_record_type_field_nth(ptr.get(), nth, &name_ptr,
602 &name_len, &type_ret)) {
603 return std::make_pair(std::string_view(name_ptr, name_len),
604 ValType(std::move(type_ret)));
605 }
606 return std::nullopt;
607}
608
609inline std::optional<ValType> TupleType::types_nth(size_t nth) const {
611 if (wasmtime_component_tuple_type_types_nth(ptr.get(), nth, &type_ret)) {
612 return ValType(std::move(type_ret));
613 }
614 return std::nullopt;
615}
616
617inline std::optional<std::pair<std::string_view, std::optional<ValType>>>
618VariantType::case_nth(size_t nth) const {
619 const char *name_ptr = nullptr;
620 size_t name_len = 0;
621 bool has_payload = false;
624 ptr.get(), nth, &name_ptr, &name_len, &has_payload, &payload_ret)) {
625 return std::nullopt;
626 }
627 return std::make_pair(
628 std::string_view(name_ptr, name_len),
629 has_payload ? std::optional<ValType>(ValType(std::move(payload_ret)))
630 : std::nullopt);
631}
632
633inline ValType OptionType::ty() const {
635 wasmtime_component_option_type_ty(ptr.get(), &type_ret);
636 return ValType(std::move(type_ret));
637}
638
639inline std::optional<ValType> ResultType::ok() const {
641 if (wasmtime_component_result_type_ok(ptr.get(), &type_ret)) {
642 return ValType(std::move(type_ret));
643 }
644 return std::nullopt;
645}
646
647inline std::optional<ValType> ResultType::err() const {
649 if (wasmtime_component_result_type_err(ptr.get(), &type_ret)) {
650 return ValType(std::move(type_ret));
651 }
652 return std::nullopt;
653}
654
655inline std::optional<ValType> FutureType::ty() const {
657 if (wasmtime_component_future_type_ty(ptr.get(), &type_ret)) {
658 return ValType(std::move(type_ret));
659 }
660 return std::nullopt;
661}
662
663inline std::optional<ValType> StreamType::ty() const {
665 if (wasmtime_component_stream_type_ty(ptr.get(), &type_ret)) {
666 return ValType(std::move(type_ret));
667 }
668 return std::nullopt;
669}
670
671inline ValType MapType::key() const {
673 wasmtime_component_map_type_key(ptr.get(), &type_ret);
674 return ValType(std::move(type_ret));
675}
676
677inline ValType MapType::value() const {
679 wasmtime_component_map_type_value(ptr.get(), &type_ret);
680 return ValType(std::move(type_ret));
681}
682
683} // namespace component
684} // namespace wasmtime
685
686#endif // WASMTIME_FEATURE_COMPONENT_MODEL
687
688#endif // WASMTIME_COMPONENT_TYPES_VAL_HH
Type information about a WebAssembly value.
Definition: types/val.hh:66
Represents a component enum type.
Definition: component/types/val.hh:83
Represents a component flags type.
Definition: component/types/val.hh:129
Represents a component future type.
Definition: component/types/val.hh:164
Represents a component list type.
Definition: component/types/val.hh:26
Represents a component map type.
Definition: component/types/val.hh:184
Represents a component option type.
Definition: component/types/val.hh:106
Represents a component record type.
Definition: component/types/val.hh:36
Definition: component/types/val.hh:151
ResourceType(uint32_t ty)
Creates a new host resource type with the specified ty identifier.
Definition: component/types/val.hh:157
Represents a component result type.
Definition: component/types/val.hh:116
Represents a component stream type.
Definition: component/types/val.hh:174
Represents a component tuple type.
Definition: component/types/val.hh:52
Represents a component value type.
Definition: component/types/val.hh:197
bool is_enum() const
Returns true if this is an enum type.
Definition: component/types/val.hh:465
bool is_u32() const
Returns true if this is a u32 type.
Definition: component/types/val.hh:429
bool is_char() const
Returns true if this is a char type.
Definition: component/types/val.hh:441
ValType & operator=(const ValType &other)
Copies another type into this one.
Definition: component/types/val.hh:219
const FlagsType & flags() const
Returns the flags type, asserting that this is indeed a flags.
Definition: component/types/val.hh:549
const EnumType & enum_() const
Returns the enum type, asserting that this is indeed a enum.
Definition: component/types/val.hh:531
const ResourceType & borrow() const
Returns the borrow type, asserting that this is indeed a borrow.
Definition: component/types/val.hh:561
bool is_tuple() const
Returns true if this is a tuple type.
Definition: component/types/val.hh:457
bool is_variant() const
Returns true if this is a variant type.
Definition: component/types/val.hh:460
wasmtime_component_valtype_t * capi()
Returns the underlying C API pointer.
Definition: component/types/val.hh:587
static ValType new_s8()
Creates an s8 value type.
Definition: component/types/val.hh:263
const MapType & map() const
Returns the map type, asserting that this is indeed a map.
Definition: component/types/val.hh:579
static ValType new_s16()
Creates an s16 value type.
Definition: component/types/val.hh:268
ValType(ListType list)
Creates a list value type.
Definition: component/types/val.hh:323
const FutureType & future() const
Returns the future type, asserting that this is indeed a future.
Definition: component/types/val.hh:567
bool is_borrow() const
Returns true if this is a borrow type.
Definition: component/types/val.hh:484
wasmtime_component_valtype_kind_t kind() const
Returns the kind of this value type.
Definition: component/types/val.hh:405
static ValType new_bool()
Creates a bool value type.
Definition: component/types/val.hh:258
const wasmtime_component_valtype_t * capi() const
Returns the underlying C API pointer.
Definition: component/types/val.hh:585
ValType(ValType &&other)
Moves another type into this one.
Definition: component/types/val.hh:226
static ValType new_string()
Creates a string value type.
Definition: component/types/val.hh:318
const StreamType & stream() const
Returns the stream type, asserting that this is indeed a stream.
Definition: component/types/val.hh:573
bool is_own() const
Returns true if this is an own type.
Definition: component/types/val.hh:481
bool is_error_context() const
Returns true if this is an error context type.
Definition: component/types/val.hh:499
bool is_string() const
Returns true if this is a string type.
Definition: component/types/val.hh:444
bool is_list() const
Returns true if this is a list type.
Definition: component/types/val.hh:449
static ValType new_f32()
Creates an f32 value type.
Definition: component/types/val.hh:303
ValType(const ValType &other)
Copies another type into this one.
Definition: component/types/val.hh:214
const RecordType & record() const
Returns the record type, asserting that this is indeed a record.
Definition: component/types/val.hh:513
bool is_future() const
Returns true if this is a future type.
Definition: component/types/val.hh:489
ValType(EnumType enum_)
Creates an enum value type.
Definition: component/types/val.hh:347
ValType(ResultType result)
Creates a result value type.
Definition: component/types/val.hh:359
ValType(OptionType option)
Creates an option value type.
Definition: component/types/val.hh:353
static ValType new_u16()
Creates a u16 value type.
Definition: component/types/val.hh:288
static ValType new_u64()
Creates a u64 value type.
Definition: component/types/val.hh:298
ValType(FlagsType flags)
Creates a flags value type.
Definition: component/types/val.hh:365
bool is_f32() const
Returns true if this is an f32 type.
Definition: component/types/val.hh:435
bool is_s16() const
Returns true if this is an s16 type.
Definition: component/types/val.hh:414
static ValType new_char()
Creates a char value type.
Definition: component/types/val.hh:313
static ValType new_u8()
Creates a u8 value type.
Definition: component/types/val.hh:283
const ListType & list() const
Returns the list type, asserting that this is indeed a list.
Definition: component/types/val.hh:507
ValType(FutureType future)
Creates a future value type.
Definition: component/types/val.hh:387
ValType(VariantType variant)
Creates a variant value type.
Definition: component/types/val.hh:341
bool is_u8() const
Returns true if this is a u8 type.
Definition: component/types/val.hh:423
const TupleType & tuple() const
Returns the tuple type, asserting that this is indeed a tuple.
Definition: component/types/val.hh:519
ValType(wasmtime_component_valtype_t &&ty)
Creates a component value type from the raw C API representation.
Definition: component/types/val.hh:208
ValType(MapType map)
Creates a map value type.
Definition: component/types/val.hh:399
bool is_flags() const
Returns true if this is a flags type.
Definition: component/types/val.hh:478
static ValType new_borrow(ResourceType borrow)
Creates an borrow value type.
Definition: component/types/val.hh:379
bool operator!=(const ValType &other) const
Compares two types to see if they're different.
Definition: component/types/val.hh:255
bool is_s64() const
Returns true if this is an s64 type.
Definition: component/types/val.hh:420
ValType(RecordType record)
Creates a record value type.
Definition: component/types/val.hh:329
bool is_u64() const
Returns true if this is a u64 type.
Definition: component/types/val.hh:432
static ValType new_f64()
Creates an f64 value type.
Definition: component/types/val.hh:308
static ValType new_s64()
Creates an s64 value type.
Definition: component/types/val.hh:278
ValType & operator=(ValType &&other)
Moves another type into this one.
Definition: component/types/val.hh:231
static ValType new_s32()
Creates an s32 value type.
Definition: component/types/val.hh:273
static ValType new_u32()
Creates a u32 value type.
Definition: component/types/val.hh:293
const VariantType & variant() const
Returns the variant type, asserting that this is indeed a variant.
Definition: component/types/val.hh:525
bool is_s8() const
Returns true if this is an s8 type.
Definition: component/types/val.hh:411
ValType(StreamType stream)
Creates a stream value type.
Definition: component/types/val.hh:393
bool is_s32() const
Returns true if this is an s32 type.
Definition: component/types/val.hh:417
bool is_f64() const
Returns true if this is an f64 type.
Definition: component/types/val.hh:438
static ValType new_own(ResourceType own)
Creates an own value type.
Definition: component/types/val.hh:371
bool operator==(const ValType &other) const
Compares two types to see if they're the same.
Definition: component/types/val.hh:250
bool is_result() const
Returns true if this is a result type.
Definition: component/types/val.hh:473
bool is_record() const
Returns true if this is a record type.
Definition: component/types/val.hh:452
bool is_map() const
Returns true if this is a map type.
Definition: component/types/val.hh:504
const ResultType & result() const
Returns the result type, asserting that this is indeed a result.
Definition: component/types/val.hh:543
ValType(TupleType tuple)
Creates a tuple value type.
Definition: component/types/val.hh:335
const OptionType & option() const
Returns the option type, asserting that this is indeed a option.
Definition: component/types/val.hh:537
bool is_bool() const
Returns true if this is a bool type.
Definition: component/types/val.hh:408
bool is_u16() const
Returns true if this is a u16 type.
Definition: component/types/val.hh:426
bool is_option() const
Returns true if this is an option type.
Definition: component/types/val.hh:468
bool is_stream() const
Returns true if this is a stream type.
Definition: component/types/val.hh:494
static const ValType * from_capi(const wasmtime_component_valtype_t *capi)
Definition: component/types/val.hh:244
Represents a component variant type.
Definition: component/types/val.hh:67
WASM_API_EXTERN bool wasmtime_component_result_type_err(const wasmtime_component_result_type_t *ty, struct wasmtime_component_valtype_t *type_ret)
Returns the err type of a component result type. The returned type must be deallocated with wasmtime_...
WASM_API_EXTERN void wasmtime_component_option_type_ty(const wasmtime_component_option_type_t *ty, struct wasmtime_component_valtype_t *type_ret)
Returns the inner type of a component option type.
#define WASMTIME_COMPONENT_VALTYPE_S16
Value of wasmtime_component_valtype_kind_t meaning that wasmtime_component_valtype_t is a s16 WIT typ...
Definition: component/types/val.h:385
#define WASMTIME_COMPONENT_VALTYPE_U64
Value of wasmtime_component_valtype_kind_t meaning that wasmtime_component_valtype_t is a u64 WIT typ...
Definition: component/types/val.h:403
WASM_API_EXTERN size_t wasmtime_component_tuple_type_types_count(const wasmtime_component_tuple_type_t *ty)
Returns the number of types in a component tuple type.
WASM_API_EXTERN size_t wasmtime_component_enum_type_names_count(const wasmtime_component_enum_type_t *ty)
Returns the number of names in a component enum type.
WASM_API_EXTERN bool wasmtime_component_tuple_type_types_nth(const wasmtime_component_tuple_type_t *ty, size_t nth, struct wasmtime_component_valtype_t *type_ret)
Returns the nth type in a component tuple type.
#define WASMTIME_COMPONENT_VALTYPE_OWN
Value of wasmtime_component_valtype_kind_t meaning that wasmtime_component_valtype_t is a resource ow...
Definition: component/types/val.h:442
WASM_API_EXTERN size_t wasmtime_component_flags_type_names_count(const wasmtime_component_flags_type_t *ty)
Returns the number of names in a component flags type.
WASM_API_EXTERN size_t wasmtime_component_variant_type_case_count(const wasmtime_component_variant_type_t *ty)
Returns the number of cases in a component variant type.
WASM_API_EXTERN bool wasmtime_component_stream_type_ty(const wasmtime_component_stream_type_t *ty, struct wasmtime_component_valtype_t *type_ret)
Returns the inner type of a component stream type.
WASM_API_EXTERN void wasmtime_component_valtype_clone(const wasmtime_component_valtype_t *ty, wasmtime_component_valtype_t *out)
Clones a component value type.
WASM_API_EXTERN bool wasmtime_component_record_type_field_nth(const wasmtime_component_record_type_t *ty, size_t nth, const char **name_ret, size_t *name_len_ret, struct wasmtime_component_valtype_t *type_ret)
Returns the nth field in a component record type.
#define WASMTIME_COMPONENT_VALTYPE_STREAM
Value of wasmtime_component_valtype_kind_t meaning that wasmtime_component_valtype_t is a stream WIT ...
Definition: component/types/val.h:451
#define WASMTIME_COMPONENT_VALTYPE_S64
Value of wasmtime_component_valtype_kind_t meaning that wasmtime_component_valtype_t is a s64 WIT typ...
Definition: component/types/val.h:391
#define WASMTIME_COMPONENT_VALTYPE_F64
Value of wasmtime_component_valtype_kind_t meaning that wasmtime_component_valtype_t is a f64 WIT typ...
Definition: component/types/val.h:409
WASM_API_EXTERN bool wasmtime_component_result_type_ok(const wasmtime_component_result_type_t *ty, struct wasmtime_component_valtype_t *type_ret)
Returns the ok type of a component result type. The returned type must be deallocated with wasmtime_c...
#define WASMTIME_COMPONENT_VALTYPE_S8
Value of wasmtime_component_valtype_kind_t meaning that wasmtime_component_valtype_t is a s8 WIT type...
Definition: component/types/val.h:382
#define WASMTIME_COMPONENT_VALTYPE_BORROW
Value of wasmtime_component_valtype_kind_t meaning that wasmtime_component_valtype_t is a resource bo...
Definition: component/types/val.h:445
#define WASMTIME_COMPONENT_VALTYPE_MAP
Value of wasmtime_component_valtype_kind_t meaning that wasmtime_component_valtype_t is a map WIT typ...
Definition: component/types/val.h:457
WASM_API_EXTERN bool wasmtime_component_variant_type_case_nth(const wasmtime_component_variant_type_t *ty, size_t nth, const char **name_ret, size_t *name_len_ret, bool *has_payload_ret, struct wasmtime_component_valtype_t *payload_ret)
Returns the nth case in a component variant type. The returned payload type must be deallocated with ...
#define WASMTIME_COMPONENT_VALTYPE_STRING
Value of wasmtime_component_valtype_kind_t meaning that wasmtime_component_valtype_t is a string WIT ...
Definition: component/types/val.h:415
WASM_API_EXTERN void wasmtime_component_map_type_value(const wasmtime_component_map_type_t *ty, struct wasmtime_component_valtype_t *type_ret)
Returns the value type of a component map type.
WASM_API_EXTERN void wasmtime_component_valtype_delete(wasmtime_component_valtype_t *ptr)
Deallocates a component value type.
#define WASMTIME_COMPONENT_VALTYPE_FUTURE
Value of wasmtime_component_valtype_kind_t meaning that wasmtime_component_valtype_t is a future WIT ...
Definition: component/types/val.h:448
WASM_API_EXTERN bool wasmtime_component_future_type_ty(const wasmtime_component_future_type_t *ty, struct wasmtime_component_valtype_t *type_ret)
Returns the inner type of a component future type.
WASM_API_EXTERN bool wasmtime_component_flags_type_names_nth(const wasmtime_component_flags_type_t *ty, size_t nth, const char **name_ret, size_t *name_len_ret)
Returns the nth name in a component flags type.
WASM_API_EXTERN bool wasmtime_component_enum_type_names_nth(const wasmtime_component_enum_type_t *ty, size_t nth, const char **name_ret, size_t *name_len_ret)
Returns the nth name in a component enum type.
#define WASMTIME_COMPONENT_VALTYPE_VARIANT
Value of wasmtime_component_valtype_kind_t meaning that wasmtime_component_valtype_t is a variant WIT...
Definition: component/types/val.h:427
#define WASMTIME_COMPONENT_VALTYPE_RECORD
Value of wasmtime_component_valtype_kind_t meaning that wasmtime_component_valtype_t is a record WIT ...
Definition: component/types/val.h:421
WASM_API_EXTERN size_t wasmtime_component_record_type_field_count(const wasmtime_component_record_type_t *ty)
Returns the number of fields in a component record type.
WASM_API_EXTERN void wasmtime_component_map_type_key(const wasmtime_component_map_type_t *ty, struct wasmtime_component_valtype_t *type_ret)
Returns the key type of a component map type.
#define WASMTIME_COMPONENT_VALTYPE_BOOL
Value of wasmtime_component_valtype_kind_t meaning that wasmtime_component_valtype_t is a bool WIT ty...
Definition: component/types/val.h:379
uint8_t wasmtime_component_valtype_kind_t
Discriminant used in wasmtime_component_valtype_t::kind.
Definition: component/types/val.h:460
WASM_API_EXTERN bool wasmtime_component_valtype_equal(const wasmtime_component_valtype_t *a, const wasmtime_component_valtype_t *b)
Compares two component value types for equality.
#define WASMTIME_COMPONENT_VALTYPE_RESULT
Value of wasmtime_component_valtype_kind_t meaning that wasmtime_component_valtype_t is a result WIT ...
Definition: component/types/val.h:436
#define WASMTIME_COMPONENT_VALTYPE_ERROR_CONTEXT
Value of wasmtime_component_valtype_kind_t meaning that wasmtime_component_valtype_t is an error cont...
Definition: component/types/val.h:454
WASM_API_EXTERN void wasmtime_component_list_type_element(const wasmtime_component_list_type_t *ty, struct wasmtime_component_valtype_t *type_ret)
Returns the element type of a component list type.
#define WASMTIME_COMPONENT_VALTYPE_U32
Value of wasmtime_component_valtype_kind_t meaning that wasmtime_component_valtype_t is a u32 WIT typ...
Definition: component/types/val.h:400
#define WASMTIME_COMPONENT_VALTYPE_OPTION
Value of wasmtime_component_valtype_kind_t meaning that wasmtime_component_valtype_t is a option WIT ...
Definition: component/types/val.h:433
#define WASMTIME_COMPONENT_VALTYPE_ENUM
Value of wasmtime_component_valtype_kind_t meaning that wasmtime_component_valtype_t is a enum WIT ty...
Definition: component/types/val.h:430
#define WASMTIME_COMPONENT_VALTYPE_CHAR
Value of wasmtime_component_valtype_kind_t meaning that wasmtime_component_valtype_t is a char WIT ty...
Definition: component/types/val.h:412
#define WASMTIME_COMPONENT_VALTYPE_TUPLE
Value of wasmtime_component_valtype_kind_t meaning that wasmtime_component_valtype_t is a tuple WIT t...
Definition: component/types/val.h:424
#define WASMTIME_COMPONENT_VALTYPE_U8
Value of wasmtime_component_valtype_kind_t meaning that wasmtime_component_valtype_t is a u8 WIT type...
Definition: component/types/val.h:394
#define WASMTIME_COMPONENT_VALTYPE_F32
Value of wasmtime_component_valtype_kind_t meaning that wasmtime_component_valtype_t is a f32 WIT typ...
Definition: component/types/val.h:406
#define WASMTIME_COMPONENT_VALTYPE_LIST
Value of wasmtime_component_valtype_kind_t meaning that wasmtime_component_valtype_t is a list WIT ty...
Definition: component/types/val.h:418
#define WASMTIME_COMPONENT_VALTYPE_FLAGS
Value of wasmtime_component_valtype_kind_t meaning that wasmtime_component_valtype_t is a flags WIT t...
Definition: component/types/val.h:439
#define WASMTIME_COMPONENT_VALTYPE_S32
Value of wasmtime_component_valtype_kind_t meaning that wasmtime_component_valtype_t is a s32 WIT typ...
Definition: component/types/val.h:388
#define WASMTIME_COMPONENT_VALTYPE_U16
Value of wasmtime_component_valtype_kind_t meaning that wasmtime_component_valtype_t is a u16 WIT typ...
Definition: component/types/val.h:397
Build-time defines for how the C API was built.
WASM_API_EXTERN wasmtime_component_resource_type_t * wasmtime_component_resource_type_new_host(uint32_t ty)
Creates a new resource type representing a host-defined resource.
Represents a single value type in the component model.
Definition: component/types/val.h:506
wasmtime_component_valtype_union_t of
The actual type.
Definition: component/types/val.h:510
wasmtime_component_valtype_kind_t kind
The type discriminant for the of union.
Definition: component/types/val.h:508
wasmtime_component_flags_type_t * flags
Definition: component/types/val.h:487
wasmtime_component_option_type_t * option
Definition: component/types/val.h:481
wasmtime_component_record_type_t * record
Definition: component/types/val.h:469
wasmtime_component_resource_type_t * borrow
Definition: component/types/val.h:493
wasmtime_component_list_type_t * list
Definition: component/types/val.h:466
wasmtime_component_tuple_type_t * tuple
Definition: component/types/val.h:472
wasmtime_component_future_type_t * future
Definition: component/types/val.h:496
wasmtime_component_result_type_t * result
Definition: component/types/val.h:484
wasmtime_component_map_type_t * map
Definition: component/types/val.h:502
wasmtime_component_enum_type_t * enum_
Definition: component/types/val.h:478
wasmtime_component_stream_type_t * stream
Definition: component/types/val.h:499
wasmtime_component_variant_type_t * variant
Definition: component/types/val.h:475