1 /**
2  * \file wasmtime/component/types/val.hh
3  */
4 
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>
15 #include <wasmtime/component/types/val.h>
16 #include <wasmtime/helpers.hh>
17 
18 namespace wasmtime {
19 namespace component {
20 
21 class ValType;
22 
23 /**
24  * \brief Represents a component list type.
25  */
26 class ListType {
27   WASMTIME_CLONE_EQUAL_WRAPPER(ListType, wasmtime_component_list_type);
28 
29   /// Returns the element type of this list type.
30   ValType element() const;
31 };
32 
33 /**
34  * \brief Represents a component record type.
35  */
36 class RecordType {
37   WASMTIME_CLONE_EQUAL_WRAPPER(RecordType, wasmtime_component_record_type);
38 
39   /// Returns the number of fields in this record type.
field_count() const40   size_t field_count() const {
41     return wasmtime_component_record_type_field_count(ptr.get());
42   }
43 
44   /// Retrieves the nth field.
45   std::optional<std::pair<std::string_view, ValType>>
46   field_nth(size_t nth) const;
47 };
48 
49 /**
50  * \brief Represents a component tuple type.
51  */
52 class TupleType {
53   WASMTIME_CLONE_EQUAL_WRAPPER(TupleType, wasmtime_component_tuple_type);
54 
55   /// Returns the number of types in this tuple type.
types_count() const56   size_t types_count() const {
57     return wasmtime_component_tuple_type_types_count(ptr.get());
58   }
59 
60   /// Retrieves the nth type.
61   std::optional<ValType> types_nth(size_t nth) const;
62 };
63 
64 /**
65  * \brief Represents a component variant type.
66  */
67 class VariantType {
68   WASMTIME_CLONE_EQUAL_WRAPPER(VariantType, wasmtime_component_variant_type);
69 
70   /// Returns the number of cases in this variant type.
case_count() const71   size_t case_count() const {
72     return wasmtime_component_variant_type_case_count(ptr.get());
73   }
74 
75   /// Retrieves the nth case.
76   std::optional<std::pair<std::string_view, std::optional<ValType>>>
77   case_nth(size_t nth) const;
78 };
79 
80 /**
81  * \brief Represents a component enum type.
82  */
83 class EnumType {
84   WASMTIME_CLONE_EQUAL_WRAPPER(EnumType, wasmtime_component_enum_type);
85 
86   /// Returns the number of names in this enum type.
names_count() const87   size_t names_count() const {
88     return wasmtime_component_enum_type_names_count(ptr.get());
89   }
90 
91   /// Retrieves the nth name.
names_nth(size_t nth) const92   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 
103 /**
104  * \brief Represents a component option type.
105  */
106 class OptionType {
107   WASMTIME_CLONE_EQUAL_WRAPPER(OptionType, wasmtime_component_option_type);
108 
109   /// Returns the inner type of this option type.
110   ValType ty() const;
111 };
112 
113 /**
114  * \brief Represents a component result type.
115  */
116 class ResultType {
117   WASMTIME_CLONE_EQUAL_WRAPPER(ResultType, wasmtime_component_result_type);
118 
119   /// Returns the ok type of this result type, if any.
120   std::optional<ValType> ok() const;
121 
122   /// Returns the err type of this result type, if any.
123   std::optional<ValType> err() const;
124 };
125 
126 /**
127  * \brief Represents a component flags type.
128  */
129 class FlagsType {
130   WASMTIME_CLONE_EQUAL_WRAPPER(FlagsType, wasmtime_component_flags_type);
131 
132   /// Returns the number of names in this flags type.
names_count() const133   size_t names_count() const {
134     return wasmtime_component_flags_type_names_count(ptr.get());
135   }
136 
137   /// Retrieves the nth name.
names_nth(size_t nth) const138   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 
149 /// Class representing a component model `resource` value which is either a
150 /// guest or host-defined resource.
151 class ResourceType {
152   WASMTIME_CLONE_EQUAL_WRAPPER(ResourceType, wasmtime_component_resource_type);
153 
154 public:
155   /// \brief Creates a new host resource type with the specified `ty`
156   /// identifier.
ResourceType(uint32_t ty)157   explicit ResourceType(uint32_t ty)
158       : ptr(wasmtime_component_resource_type_new_host(ty)) {}
159 };
160 
161 /**
162  * \brief Represents a component future type.
163  */
164 class FutureType {
165   WASMTIME_CLONE_EQUAL_WRAPPER(FutureType, wasmtime_component_future_type);
166 
167   /// Returns the inner type of this future type, if any.
168   std::optional<ValType> ty() const;
169 };
170 
171 /**
172  * \brief Represents a component stream type.
173  */
174 class StreamType {
175   WASMTIME_CLONE_EQUAL_WRAPPER(StreamType, wasmtime_component_stream_type);
176 
177   /// Returns the inner type of this stream type, if any.
178   std::optional<ValType> ty() const;
179 };
180 
181 /**
182  * \brief Represents a component map type.
183  */
184 class MapType {
185   WASMTIME_CLONE_EQUAL_WRAPPER(MapType, wasmtime_component_map_type);
186 
187   /// Returns the key type of this map type.
188   ValType key() const;
189 
190   /// Returns the value type of this map type.
191   ValType value() const;
192 };
193 
194 /**
195  * \brief Represents a component value type.
196  */
197 class ValType {
198   wasmtime_component_valtype_t ty;
199 
new_kind(wasmtime_component_valtype_kind_t kind)200   static ValType new_kind(wasmtime_component_valtype_kind_t kind) {
201     wasmtime_component_valtype_t ty;
202     ty.kind = kind;
203     return ValType(std::move(ty));
204   }
205 
206 public:
207   /// Creates a component value type from the raw C API representation.
ValType(wasmtime_component_valtype_t && ty)208   explicit ValType(wasmtime_component_valtype_t &&ty) {
209     this->ty = ty;
210     ty.kind = WASMTIME_COMPONENT_VALTYPE_BOOL;
211   }
212 
213   /// Copies another type into this one.
ValType(const ValType & other)214   ValType(const ValType &other) {
215     wasmtime_component_valtype_clone(&other.ty, &ty);
216   }
217 
218   /// Copies another type into this one.
operator =(const ValType & other)219   ValType &operator=(const ValType &other) {
220     wasmtime_component_valtype_delete(&ty);
221     wasmtime_component_valtype_clone(&other.ty, &ty);
222     return *this;
223   }
224 
225   /// Moves another type into this one.
ValType(ValType && other)226   ValType(ValType &&other) : ty(other.ty) {
227     other.ty.kind = WASMTIME_COMPONENT_VALTYPE_BOOL;
228   }
229 
230   /// Moves another type into this one.
operator =(ValType && other)231   ValType &operator=(ValType &&other) {
232     wasmtime_component_valtype_delete(&ty);
233     ty = other.ty;
234     other.ty.kind = WASMTIME_COMPONENT_VALTYPE_BOOL;
235     return *this;
236   }
237 
~ValType()238   ~ValType() { wasmtime_component_valtype_delete(&ty); }
239 
240   /**
241    * Converts the raw C API representation to this class without taking
242    * ownership.
243    */
from_capi(const wasmtime_component_valtype_t * capi)244   static const ValType *from_capi(const wasmtime_component_valtype_t *capi) {
245     static_assert(sizeof(ValType) == sizeof(wasmtime_component_valtype_t));
246     return reinterpret_cast<const ValType *>(capi);
247   }
248 
249   /// \brief Compares two types to see if they're the same.
operator ==(const ValType & other) const250   bool operator==(const ValType &other) const {
251     return wasmtime_component_valtype_equal(&ty, &other.ty);
252   }
253 
254   /// \brief Compares two types to see if they're different.
operator !=(const ValType & other) const255   bool operator!=(const ValType &other) const { return !(*this == other); }
256 
257   /// Creates a bool value type.
new_bool()258   static ValType new_bool() {
259     return ValType::new_kind(WASMTIME_COMPONENT_VALTYPE_BOOL);
260   }
261 
262   /// Creates an s8 value type.
new_s8()263   static ValType new_s8() {
264     return ValType::new_kind(WASMTIME_COMPONENT_VALTYPE_S8);
265   }
266 
267   /// Creates an s16 value type.
new_s16()268   static ValType new_s16() {
269     return ValType::new_kind(WASMTIME_COMPONENT_VALTYPE_S16);
270   }
271 
272   /// Creates an s32 value type.
new_s32()273   static ValType new_s32() {
274     return ValType::new_kind(WASMTIME_COMPONENT_VALTYPE_S32);
275   }
276 
277   /// Creates an s64 value type.
new_s64()278   static ValType new_s64() {
279     return ValType::new_kind(WASMTIME_COMPONENT_VALTYPE_S64);
280   }
281 
282   /// Creates a u8 value type.
new_u8()283   static ValType new_u8() {
284     return ValType::new_kind(WASMTIME_COMPONENT_VALTYPE_U8);
285   }
286 
287   /// Creates a u16 value type.
new_u16()288   static ValType new_u16() {
289     return ValType::new_kind(WASMTIME_COMPONENT_VALTYPE_U16);
290   }
291 
292   /// Creates a u32 value type.
new_u32()293   static ValType new_u32() {
294     return ValType::new_kind(WASMTIME_COMPONENT_VALTYPE_U32);
295   }
296 
297   /// Creates a u64 value type.
new_u64()298   static ValType new_u64() {
299     return ValType::new_kind(WASMTIME_COMPONENT_VALTYPE_U64);
300   }
301 
302   /// Creates an f32 value type.
new_f32()303   static ValType new_f32() {
304     return ValType::new_kind(WASMTIME_COMPONENT_VALTYPE_F32);
305   }
306 
307   /// Creates an f64 value type.
new_f64()308   static ValType new_f64() {
309     return ValType::new_kind(WASMTIME_COMPONENT_VALTYPE_F64);
310   }
311 
312   /// Creates a char value type.
new_char()313   static ValType new_char() {
314     return ValType::new_kind(WASMTIME_COMPONENT_VALTYPE_CHAR);
315   }
316 
317   /// Creates a string value type.
new_string()318   static ValType new_string() {
319     return ValType::new_kind(WASMTIME_COMPONENT_VALTYPE_STRING);
320   }
321 
322   /// Creates a list value type.
ValType(ListType list)323   ValType(ListType list) {
324     ty.kind = WASMTIME_COMPONENT_VALTYPE_LIST;
325     ty.of.list = list.capi_release();
326   }
327 
328   /// Creates a record value type.
ValType(RecordType record)329   ValType(RecordType record) {
330     ty.kind = WASMTIME_COMPONENT_VALTYPE_RECORD;
331     ty.of.record = record.capi_release();
332   }
333 
334   /// Creates a tuple value type.
ValType(TupleType tuple)335   ValType(TupleType tuple) {
336     ty.kind = WASMTIME_COMPONENT_VALTYPE_TUPLE;
337     ty.of.tuple = tuple.capi_release();
338   }
339 
340   /// Creates a variant value type.
ValType(VariantType variant)341   ValType(VariantType variant) {
342     ty.kind = WASMTIME_COMPONENT_VALTYPE_VARIANT;
343     ty.of.variant = variant.capi_release();
344   }
345 
346   /// Creates an enum value type.
ValType(EnumType enum_)347   ValType(EnumType enum_) {
348     ty.kind = WASMTIME_COMPONENT_VALTYPE_ENUM;
349     ty.of.enum_ = enum_.capi_release();
350   }
351 
352   /// Creates an option value type.
ValType(OptionType option)353   ValType(OptionType option) {
354     ty.kind = WASMTIME_COMPONENT_VALTYPE_OPTION;
355     ty.of.option = option.capi_release();
356   }
357 
358   /// Creates a result value type.
ValType(ResultType result)359   ValType(ResultType result) {
360     ty.kind = WASMTIME_COMPONENT_VALTYPE_RESULT;
361     ty.of.result = result.capi_release();
362   }
363 
364   /// Creates a flags value type.
ValType(FlagsType flags)365   ValType(FlagsType flags) {
366     ty.kind = WASMTIME_COMPONENT_VALTYPE_FLAGS;
367     ty.of.flags = flags.capi_release();
368   }
369 
370   /// Creates an own value type.
new_own(ResourceType own)371   static ValType new_own(ResourceType own) {
372     wasmtime_component_valtype_t ty;
373     ty.kind = WASMTIME_COMPONENT_VALTYPE_OWN;
374     ty.of.own = own.capi_release();
375     return ValType(std::move(ty));
376   }
377 
378   /// Creates an borrow value type.
new_borrow(ResourceType borrow)379   static ValType new_borrow(ResourceType borrow) {
380     wasmtime_component_valtype_t ty;
381     ty.kind = WASMTIME_COMPONENT_VALTYPE_BORROW;
382     ty.of.borrow = borrow.capi_release();
383     return ValType(std::move(ty));
384   }
385 
386   /// Creates a future value type.
ValType(FutureType future)387   ValType(FutureType future) {
388     ty.kind = WASMTIME_COMPONENT_VALTYPE_FUTURE;
389     ty.of.future = future.capi_release();
390   }
391 
392   /// Creates a stream value type.
ValType(StreamType stream)393   ValType(StreamType stream) {
394     ty.kind = WASMTIME_COMPONENT_VALTYPE_STREAM;
395     ty.of.stream = stream.capi_release();
396   }
397 
398   /// Creates a map value type.
ValType(MapType map)399   ValType(MapType map) {
400     ty.kind = WASMTIME_COMPONENT_VALTYPE_MAP;
401     ty.of.map = map.capi_release();
402   }
403 
404   /// Returns the kind of this value type.
kind() const405   wasmtime_component_valtype_kind_t kind() const { return ty.kind; }
406 
407   /// Returns true if this is a bool type.
is_bool() const408   bool is_bool() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_BOOL; }
409 
410   /// Returns true if this is an s8 type.
is_s8() const411   bool is_s8() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_S8; }
412 
413   /// Returns true if this is an s16 type.
is_s16() const414   bool is_s16() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_S16; }
415 
416   /// Returns true if this is an s32 type.
is_s32() const417   bool is_s32() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_S32; }
418 
419   /// Returns true if this is an s64 type.
is_s64() const420   bool is_s64() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_S64; }
421 
422   /// Returns true if this is a u8 type.
is_u8() const423   bool is_u8() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_U8; }
424 
425   /// Returns true if this is a u16 type.
is_u16() const426   bool is_u16() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_U16; }
427 
428   /// Returns true if this is a u32 type.
is_u32() const429   bool is_u32() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_U32; }
430 
431   /// Returns true if this is a u64 type.
is_u64() const432   bool is_u64() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_U64; }
433 
434   /// Returns true if this is an f32 type.
is_f32() const435   bool is_f32() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_F32; }
436 
437   /// Returns true if this is an f64 type.
is_f64() const438   bool is_f64() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_F64; }
439 
440   /// Returns true if this is a char type.
is_char() const441   bool is_char() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_CHAR; }
442 
443   /// Returns true if this is a string type.
is_string() const444   bool is_string() const {
445     return ty.kind == WASMTIME_COMPONENT_VALTYPE_STRING;
446   }
447 
448   /// Returns true if this is a list type.
is_list() const449   bool is_list() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_LIST; }
450 
451   /// Returns true if this is a record type.
is_record() const452   bool is_record() const {
453     return ty.kind == WASMTIME_COMPONENT_VALTYPE_RECORD;
454   }
455 
456   /// Returns true if this is a tuple type.
is_tuple() const457   bool is_tuple() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_TUPLE; }
458 
459   /// Returns true if this is a variant type.
is_variant() const460   bool is_variant() const {
461     return ty.kind == WASMTIME_COMPONENT_VALTYPE_VARIANT;
462   }
463 
464   /// Returns true if this is an enum type.
is_enum() const465   bool is_enum() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_ENUM; }
466 
467   /// Returns true if this is an option type.
is_option() const468   bool is_option() const {
469     return ty.kind == WASMTIME_COMPONENT_VALTYPE_OPTION;
470   }
471 
472   /// Returns true if this is a result type.
is_result() const473   bool is_result() const {
474     return ty.kind == WASMTIME_COMPONENT_VALTYPE_RESULT;
475   }
476 
477   /// Returns true if this is a flags type.
is_flags() const478   bool is_flags() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_FLAGS; }
479 
480   /// Returns true if this is an own type.
is_own() const481   bool is_own() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_OWN; }
482 
483   /// Returns true if this is a borrow type.
is_borrow() const484   bool is_borrow() const {
485     return ty.kind == WASMTIME_COMPONENT_VALTYPE_BORROW;
486   }
487 
488   /// Returns true if this is a future type.
is_future() const489   bool is_future() const {
490     return ty.kind == WASMTIME_COMPONENT_VALTYPE_FUTURE;
491   }
492 
493   /// Returns true if this is a stream type.
is_stream() const494   bool is_stream() const {
495     return ty.kind == WASMTIME_COMPONENT_VALTYPE_STREAM;
496   }
497 
498   /// Returns true if this is an error context type.
is_error_context() const499   bool is_error_context() const {
500     return ty.kind == WASMTIME_COMPONENT_VALTYPE_ERROR_CONTEXT;
501   }
502 
503   /// Returns true if this is a map type.
is_map() const504   bool is_map() const { return ty.kind == WASMTIME_COMPONENT_VALTYPE_MAP; }
505 
506   /// Returns the list type, asserting that this is indeed a list.
list() const507   const ListType &list() const {
508     assert(is_list());
509     return *ListType::from_capi(&ty.of.list);
510   }
511 
512   /// Returns the record type, asserting that this is indeed a record.
record() const513   const RecordType &record() const {
514     assert(is_record());
515     return *RecordType::from_capi(&ty.of.record);
516   }
517 
518   /// Returns the tuple type, asserting that this is indeed a tuple.
tuple() const519   const TupleType &tuple() const {
520     assert(is_tuple());
521     return *TupleType::from_capi(&ty.of.tuple);
522   }
523 
524   /// Returns the variant type, asserting that this is indeed a variant.
variant() const525   const VariantType &variant() const {
526     assert(is_variant());
527     return *VariantType::from_capi(&ty.of.variant);
528   }
529 
530   /// Returns the enum type, asserting that this is indeed a enum.
enum_() const531   const EnumType &enum_() const {
532     assert(is_enum());
533     return *EnumType::from_capi(&ty.of.enum_);
534   }
535 
536   /// Returns the option type, asserting that this is indeed a option.
option() const537   const OptionType &option() const {
538     assert(is_option());
539     return *OptionType::from_capi(&ty.of.option);
540   }
541 
542   /// Returns the result type, asserting that this is indeed a result.
result() const543   const ResultType &result() const {
544     assert(is_result());
545     return *ResultType::from_capi(&ty.of.result);
546   }
547 
548   /// Returns the flags type, asserting that this is indeed a flags.
flags() const549   const FlagsType &flags() const {
550     assert(is_flags());
551     return *FlagsType::from_capi(&ty.of.flags);
552   }
553 
554   /// Returns the own type, asserting that this is indeed a own.
own() const555   const ResourceType &own() const {
556     assert(is_own());
557     return *ResourceType::from_capi(&ty.of.own);
558   }
559 
560   /// Returns the borrow type, asserting that this is indeed a borrow.
borrow() const561   const ResourceType &borrow() const {
562     assert(is_borrow());
563     return *ResourceType::from_capi(&ty.of.borrow);
564   }
565 
566   /// Returns the future type, asserting that this is indeed a future.
future() const567   const FutureType &future() const {
568     assert(is_future());
569     return *FutureType::from_capi(&ty.of.future);
570   }
571 
572   /// Returns the stream type, asserting that this is indeed a stream.
stream() const573   const StreamType &stream() const {
574     assert(is_stream());
575     return *StreamType::from_capi(&ty.of.stream);
576   }
577 
578   /// Returns the map type, asserting that this is indeed a map.
map() const579   const MapType &map() const {
580     assert(is_map());
581     return *MapType::from_capi(&ty.of.map);
582   }
583 
584   /// \brief Returns the underlying C API pointer.
capi() const585   const wasmtime_component_valtype_t *capi() const { return &ty; }
586   /// \brief Returns the underlying C API pointer.
capi()587   wasmtime_component_valtype_t *capi() { return &ty; }
588 };
589 
element() const590 inline ValType ListType::element() const {
591   wasmtime_component_valtype_t type_ret;
592   wasmtime_component_list_type_element(ptr.get(), &type_ret);
593   return ValType(std::move(type_ret));
594 }
595 
596 inline std::optional<std::pair<std::string_view, ValType>>
field_nth(size_t nth) const597 RecordType::field_nth(size_t nth) const {
598   const char *name_ptr = nullptr;
599   size_t name_len = 0;
600   wasmtime_component_valtype_t type_ret;
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 
types_nth(size_t nth) const609 inline std::optional<ValType> TupleType::types_nth(size_t nth) const {
610   wasmtime_component_valtype_t type_ret;
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 
617 inline std::optional<std::pair<std::string_view, std::optional<ValType>>>
case_nth(size_t nth) const618 VariantType::case_nth(size_t nth) const {
619   const char *name_ptr = nullptr;
620   size_t name_len = 0;
621   bool has_payload = false;
622   wasmtime_component_valtype_t payload_ret;
623   if (!wasmtime_component_variant_type_case_nth(
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 
ty() const633 inline ValType OptionType::ty() const {
634   wasmtime_component_valtype_t type_ret;
635   wasmtime_component_option_type_ty(ptr.get(), &type_ret);
636   return ValType(std::move(type_ret));
637 }
638 
ok() const639 inline std::optional<ValType> ResultType::ok() const {
640   wasmtime_component_valtype_t type_ret;
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 
err() const647 inline std::optional<ValType> ResultType::err() const {
648   wasmtime_component_valtype_t type_ret;
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 
ty() const655 inline std::optional<ValType> FutureType::ty() const {
656   wasmtime_component_valtype_t type_ret;
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 
ty() const663 inline std::optional<ValType> StreamType::ty() const {
664   wasmtime_component_valtype_t type_ret;
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 
key() const671 inline ValType MapType::key() const {
672   wasmtime_component_valtype_t type_ret;
673   wasmtime_component_map_type_key(ptr.get(), &type_ret);
674   return ValType(std::move(type_ret));
675 }
676 
value() const677 inline ValType MapType::value() const {
678   wasmtime_component_valtype_t type_ret;
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
689