# `Wasmex.Components.Component`

A WebAssembly Component that can be instantiated.

Components are compiled WebAssembly modules that follow the Component Model specification.
They define imports and exports using WIT (WebAssembly Interface Types).

# `t`

```elixir
@type t() :: %Wasmex.Components.Component{reference: reference(), resource: binary()}
```

# `new`

Compiles a new WebAssembly component from bytes.

## Parameters
  * `store` - The store to compile the component for
  * `bytes` - Raw WebAssembly component bytes

## Returns
  * `{:ok, component}` on success
  * `{:error, reason}` on failure

# `serialize`

```elixir
@spec serialize(t()) :: {:ok, binary()} | {:error, binary()}
```

Serializes a compiled WebAssembly component into an artifact for
`unsafe_deserialize/2` or `unsafe_deserialize_file/2`.

# `unsafe_deserialize`

```elixir
@spec unsafe_deserialize(binary(), Wasmex.Engine.t()) ::
  {:ok, t()} | {:error, binary()}
```

Loads a component artifact produced by `serialize/1` or
`Wasmex.Engine.precompile_component/2`.

The artifact must match the Wasmtime version, target, and compatible
configuration of the supplied Engine. Create the component Store with
this same Engine before instantiating the component.

## Safety

Only pass unmodified artifacts from a trusted Wasmtime compiler. The
artifact contains native executable code. Wasmtime's compatibility checks
cannot establish that the code is safe to run. Keep this API away from
untrusted input.

# `unsafe_deserialize_file`

```elixir
@spec unsafe_deserialize_file(String.t(), Wasmex.Engine.t()) ::
  {:ok, t()} | {:error, binary()}
```

Loads a precompiled component by memory-mapping its artifact file.

The file must contain the output of `serialize/1` or
`Wasmex.Engine.precompile_component/2` and match the supplied Engine's
Wasmtime version, target, and configuration. Use the same Engine to create
the component Store before instantiating the component.

## Safety

Only load unmodified artifacts from a trusted Wasmtime compiler. They
contain native executable code, and the mapped file must stay unchanged
for the lifetime of the component and all instances created from it.
Use a versioned artifact path when deploying updated files.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
