Wasmtime
component/types/component.h File Reference

Go to the source code of this file.

Data Structures

union  wasmtime_component_item_union
 Represents a single item in a component's import or export list. More...
 
struct  wasmtime_component_item_t
 Represents a single item in a component's import or export list. More...
 

Macros

#define WASMTIME_COMPONENT_ITEM_COMPONENT   0
 Value of wasmtime_component_item_kind_t meaning that wasmtime_component_item_t is a component.
 
#define WASMTIME_COMPONENT_ITEM_COMPONENT_INSTANCE   1
 Value of wasmtime_component_item_kind_t meaning that wasmtime_component_item_t is a component instance.
 
#define WASMTIME_COMPONENT_ITEM_MODULE   2
 Value of wasmtime_component_item_kind_t meaning that wasmtime_component_item_t is a module.
 
#define WASMTIME_COMPONENT_ITEM_COMPONENT_FUNC   3
 Value of wasmtime_component_item_kind_t meaning that wasmtime_component_item_t is a component function.
 
#define WASMTIME_COMPONENT_ITEM_RESOURCE   4
 Value of wasmtime_component_item_kind_t meaning that wasmtime_component_item_t is a resource.
 
#define WASMTIME_COMPONENT_ITEM_CORE_FUNC   5
 Value of wasmtime_component_item_kind_t meaning that wasmtime_component_item_t is a core function.
 
#define WASMTIME_COMPONENT_ITEM_TYPE   6
 Value of wasmtime_component_item_kind_t meaning that wasmtime_component_item_t is a type.
 

Typedefs

typedef struct wasmtime_component_type_t wasmtime_component_type_t
 Represents the type of a WebAssembly component.
 
typedef uint8_t wasmtime_component_item_kind_t
 Discriminant used in wasmtime_component_item_t::kind.
 
typedef union wasmtime_component_item_union wasmtime_component_item_union_t
 Represents a single item in a component's import or export list.
 
typedef struct wasmtime_component_item_t wasmtime_component_item_t
 Represents a single item in a component's import or export list.
 
typedef struct wasmtime_component_extern_t wasmtime_component_extern_t
 Full description of a single component or component instance export or import. More...
 

Functions

WASM_API_EXTERN wasmtime_component_type_twasmtime_component_type_clone (const wasmtime_component_type_t *ty)
 Clones a component type. More...
 
WASM_API_EXTERN void wasmtime_component_type_delete (wasmtime_component_type_t *ty)
 Deallocates a component type.
 
WASM_API_EXTERN size_t wasmtime_component_type_import_count (const wasmtime_component_type_t *ty, const wasm_engine_t *engine)
 Returns the number of imports of a component type.
 
WASM_API_EXTERN bool wasmtime_component_type_import_get (const wasmtime_component_type_t *ty, const wasm_engine_t *engine, const char *name, size_t name_len, struct wasmtime_component_extern_t **ret)
 Retrieves the import with the specified name. More...
 
WASM_API_EXTERN bool wasmtime_component_type_import_nth (const wasmtime_component_type_t *ty, const wasm_engine_t *engine, size_t nth, const char **name_ret, size_t *name_len_ret, struct wasmtime_component_extern_t **ret)
 Retrieves the nth import. More...
 
WASM_API_EXTERN size_t wasmtime_component_type_export_count (const wasmtime_component_type_t *ty, const wasm_engine_t *engine)
 Returns the number of exports of a component type.
 
WASM_API_EXTERN bool wasmtime_component_type_export_get (const wasmtime_component_type_t *ty, const wasm_engine_t *engine, const char *name, size_t name_len, struct wasmtime_component_extern_t **ret)
 Retrieves the export with the specified name. More...
 
WASM_API_EXTERN bool wasmtime_component_type_export_nth (const wasmtime_component_type_t *ty, const wasm_engine_t *engine, size_t nth, const char **name_ret, size_t *name_len_ret, struct wasmtime_component_extern_t **ret)
 Retrieves the nth export. More...
 
WASM_API_EXTERN void wasmtime_component_item_clone (const wasmtime_component_item_t *item, wasmtime_component_item_t *out)
 Clones a component item. More...
 
WASM_API_EXTERN void wasmtime_component_item_delete (wasmtime_component_item_t *ptr)
 Deallocates a component item.
 
WASM_API_EXTERN wasmtime_component_extern_twasmtime_component_extern_clone (const wasmtime_component_extern_t *e)
 Clones a component extern. More...
 
WASM_API_EXTERN void wasmtime_component_extern_type (const wasmtime_component_extern_t *e, wasmtime_component_item_t *ret)
 Returns the type of the item that this import/export refers to. More...
 
WASM_API_EXTERN const char * wasmtime_component_extern_implements (const wasmtime_component_extern_t *e, size_t *len)
 Returns the implements attribute of this import/export. More...
 
WASM_API_EXTERN bool wasmtime_component_extern_is_implements (const wasmtime_component_extern_t *e, const char *name, size_t len)
 Returns whether this import/export e has an implements attribute which matches the name provided (which is len bytes long). More...
 
WASM_API_EXTERN const char * wasmtime_component_extern_external_id (const wasmtime_component_extern_t *e, size_t *len)
 Returns the external-id attribute of this import/export. More...
 
WASM_API_EXTERN void wasmtime_component_extern_delete (wasmtime_component_extern_t *ptr)
 Deallocates a component extern.
 

Typedef Documentation

◆ wasmtime_component_extern_t

Full description of a single component or component instance export or import.

This carries the type of the item being imported or exported along with any metadata attached to it such as (implements "...") or (external-id "...") annotations.

Note that this structure contains pointers to the original component or instance type that it's acquired from. This must always be destroyed/accessed before those original types are destroyed.

Function Documentation

◆ wasmtime_component_extern_clone()

WASM_API_EXTERN wasmtime_component_extern_t * wasmtime_component_extern_clone ( const wasmtime_component_extern_t e)

Clones a component extern.

The returned pointer must be deallocated with wasmtime_component_extern_delete.

Note that this does not clone the internal pointers that the wasmtime_component_extern_t struct refers to, so the returned structure still cannot outlive the original source that this comes from.

◆ wasmtime_component_extern_external_id()

WASM_API_EXTERN const char * wasmtime_component_extern_external_id ( const wasmtime_component_extern_t e,
size_t *  len 
)

Returns the external-id attribute of this import/export.

Returns NULL if this isn't present. Writes the length of the return value to len. The returned pointer cannot be used outside the lifetime of e.

◆ wasmtime_component_extern_implements()

WASM_API_EXTERN const char * wasmtime_component_extern_implements ( const wasmtime_component_extern_t e,
size_t *  len 
)

Returns the implements attribute of this import/export.

Returns NULL if this isn't present. Writes the length of the return value to len. The returned pointer cannot be used outside the lifetime of e.

◆ wasmtime_component_extern_is_implements()

WASM_API_EXTERN bool wasmtime_component_extern_is_implements ( const wasmtime_component_extern_t e,
const char *  name,
size_t  len 
)

Returns whether this import/export e has an implements attribute which matches the name provided (which is len bytes long).

This returns false if e has no implements attribute. Otherwise this returns true if the attribute is exactly equal to name or if it's a semver-compatible version of name. For example (implements "a:b/c@1.1.0") matches both a:b/c@1.0.0 and a:b/c@1.2.0.

◆ wasmtime_component_extern_type()

WASM_API_EXTERN void wasmtime_component_extern_type ( const wasmtime_component_extern_t e,
wasmtime_component_item_t ret 
)

Returns the type of the item that this import/export refers to.

The returned wasmtime_component_item_t must be deallocated with wasmtime_component_item_delete.

◆ wasmtime_component_item_clone()

WASM_API_EXTERN void wasmtime_component_item_clone ( const wasmtime_component_item_t item,
wasmtime_component_item_t out 
)

Clones a component item.

The returned pointer must be deallocated with wasmtime_component_item_delete.

◆ wasmtime_component_type_clone()

WASM_API_EXTERN wasmtime_component_type_t * wasmtime_component_type_clone ( const wasmtime_component_type_t ty)

Clones a component type.

The returned pointer must be deallocated with wasmtime_component_type_delete.

◆ wasmtime_component_type_export_get()

WASM_API_EXTERN bool wasmtime_component_type_export_get ( const wasmtime_component_type_t ty,
const wasm_engine_t engine,
const char *  name,
size_t  name_len,
struct wasmtime_component_extern_t **  ret 
)

Retrieves the export with the specified name.

The returned wasmtime_component_extern_t must be deallocated with wasmtime_component_extern_delete.

◆ wasmtime_component_type_export_nth()

WASM_API_EXTERN bool wasmtime_component_type_export_nth ( const wasmtime_component_type_t ty,
const wasm_engine_t engine,
size_t  nth,
const char **  name_ret,
size_t *  name_len_ret,
struct wasmtime_component_extern_t **  ret 
)

Retrieves the nth export.

The returned wasmtime_component_extern_t must be deallocated with wasmtime_component_extern_delete.

◆ wasmtime_component_type_import_get()

WASM_API_EXTERN bool wasmtime_component_type_import_get ( const wasmtime_component_type_t ty,
const wasm_engine_t engine,
const char *  name,
size_t  name_len,
struct wasmtime_component_extern_t **  ret 
)

Retrieves the import with the specified name.

The returned wasmtime_component_extern_t must be deallocated with wasmtime_component_extern_delete.

◆ wasmtime_component_type_import_nth()

WASM_API_EXTERN bool wasmtime_component_type_import_nth ( const wasmtime_component_type_t ty,
const wasm_engine_t engine,
size_t  nth,
const char **  name_ret,
size_t *  name_len_ret,
struct wasmtime_component_extern_t **  ret 
)

Retrieves the nth import.

The returned wasmtime_component_extern_t must be deallocated with wasmtime_component_extern_delete.