Wasmtime
wasmtime::component::Component Class Reference

Representation of a compiled WebAssembly component. More...

#include <component.hh>

Public Member Functions

 Component (const Component &other)
 Copies another component into this one.
 
Componentoperator= (const Component &other)
 Copies another component into this one.
 
 Component (Component &&other)=default
 Moves resources from another component into this one.
 
Componentoperator= (Component &&other)=default
 Moves resources from another component into this one.
 
const wasmtime_component_tcapi () const
 Returns the underlying C API pointer.
 
wasmtime_component_tcapi ()
 Returns the underlying C API pointer.
 
Result< std::vector< uint8_t > > serialize () const
 Serializes this component to a list of bytes. More...
 
std::optional< ExportIndexexport_index (ExportIndex *instance, std::string_view name)
 Returns the export index for the export named name in this component. More...
 

Static Public Member Functions

static Result< Componentcompile (Engine &engine, std::string_view wat)
 Compiles a component from the WebAssembly text format. More...
 
static Result< Componentcompile (Engine &engine, Span< uint8_t > wasm)
 Compiles a component from the WebAssembly binary format. More...
 
static Result< Componentdeserialize (Engine &engine, Span< uint8_t > wasm)
 Deserializes a previous list of bytes created with serialize. More...
 
static Result< Componentdeserialize_file (Engine &engine, const std::string &path)
 Deserializes a component from an on-disk file. More...
 

Detailed Description

Representation of a compiled WebAssembly component.

Member Function Documentation

◆ compile() [1/2]

static Result< Component > wasmtime::component::Component::compile ( Engine engine,
Span< uint8_t >  wasm 
)
inlinestatic

Compiles a component from the WebAssembly binary format.

This function compiles the provided WebAssembly binary specified by wasm within the compilation settings configured by engine. This method is synchronous and will not return until the component has finished compiling.

This function can fail if the WebAssembly binary is invalid or doesn't validate (or similar). Note that this API does not compile WebAssembly modules, which is done with Module instead of Component.

◆ compile() [2/2]

static Result< Component > wasmtime::component::Component::compile ( Engine engine,
std::string_view  wat 
)
inlinestatic

Compiles a component from the WebAssembly text format.

This function will automatically use wat2wasm on the input and then delegate to the compile function.

◆ deserialize()

static Result< Component > wasmtime::component::Component::deserialize ( Engine engine,
Span< uint8_t >  wasm 
)
inlinestatic

Deserializes a previous list of bytes created with serialize.

This function is intended to be much faster than compile where it uses the artifacts of a previous compilation to quickly create an in-memory component ready for instantiation.

It is not safe to pass arbitrary input to this function, it is only safe to pass in output from previous calls to serialize. For more information see the Rust documentation - https://docs.wasmtime.dev/api/wasmtime/struct.Module.html#method.deserialize

◆ deserialize_file()

static Result< Component > wasmtime::component::Component::deserialize_file ( Engine engine,
const std::string &  path 
)
inlinestatic

Deserializes a component from an on-disk file.

This function is the same as deserialize except that it reads the data for the serialized component from the path on disk. This can be faster than the alternative which may require copying the data around.

It is not safe to pass arbitrary input to this function, it is only safe to pass in output from previous calls to serialize. For more information see the Rust documentation - https://docs.wasmtime.dev/api/wasmtime/struct.Module.html#method.deserialize

◆ export_index()

std::optional< ExportIndex > wasmtime::component::Component::export_index ( ExportIndex instance,
std::string_view  name 
)
inline

Returns the export index for the export named name in this component.

The instance argument is an optionally provided index which is the instance under which the name should be looked up.

◆ serialize()

Result< std::vector< uint8_t > > wasmtime::component::Component::serialize ( ) const
inline

Serializes this component to a list of bytes.

The returned bytes can then be used to later pass to deserialize to quickly recreate this component in a different process perhaps.


The documentation for this class was generated from the following file: