MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / convert_to_component

Function convert_to_component

examples/component/main.rs:29–36  ·  view source on GitHub ↗

This function is only needed until rust can natively output a component. Generally embeddings should not be expected to do this programmatically, but instead language specific tooling should be used, for example in Rust `cargo component` is a good way of doing that: https://github.com/bytecodealliance/cargo-component In this example we convert the code here to simplify the testing process and bu

(path: impl AsRef<Path>)

Source from the content-addressed store, hash-verified

27///
28/// In this example we convert the code here to simplify the testing process and build system.
29fn convert_to_component(path: impl AsRef<Path>) -> Result<Vec<u8>> {
30 let bytes = &fs::read(&path).context("failed to read input file")?;
31 wit_component::ComponentEncoder::default()
32 .module(&bytes)
33 .to_wasmtime_result()?
34 .encode()
35 .to_wasmtime_result()
36}
37
38fn main() -> Result<()> {
39 // Create an engine with the component model enabled (disabled by default).

Callers 1

mainFunction · 0.85

Calls 5

to_wasmtime_resultMethod · 0.80
readFunction · 0.50
contextMethod · 0.45
encodeMethod · 0.45
moduleMethod · 0.45

Tested by

no test coverage detected