# `Plushie.Transport`
[🔗](https://github.com/plushie-ui/plushie-elixir/blob/v0.7.2/lib/plushie/transport.ex#L1)

Behaviour for renderer transport backends.

A transport handles the low-level I/O between the bridge and the
renderer process: opening the connection, sending data, receiving
incoming messages, and closing the connection.

Two implementations are provided:

- `Plushie.Transport.Port` handles `:spawn` (child process via
  Erlang Port) and `:stdio` (BEAM's own stdin/stdout) modes.
- `Plushie.Transport.IOStream` handles `{:iostream, pid}` mode
  for custom transports (SSH, TCP, WebSocket adapters).

# `t`

```elixir
@type t() :: struct()
```

# `close`

```elixir
@callback close(state :: t()) :: :ok
```

Close the transport. Called during terminate.

# `handle_info`

```elixir
@callback handle_info(message :: term(), state :: t()) ::
  {:data, binary(), t()} | {:closed, term(), t()} | :ignore
```

Handle an incoming message that may belong to this transport.

Returns:
- `{:data, binary, state}` when the message contains renderer data
- `{:closed, reason, state}` when the transport has closed
- `:ignore` when the message is not relevant to this transport

# `init`

```elixir
@callback init(opts :: keyword()) :: {:ok, t()} | {:error, term()}
```

Initialize the transport. Returns `{:ok, state}` on success.

Called once during bridge init to open the connection.

# `reopen`
*optional* 

```elixir
@callback reopen(state :: t()) :: {:ok, t()} | {:error, term()}
```

Re-open the transport connection (e.g. after crash or dev rebuild).

Only meaningful for transports where `restartable?/1` returns `true`.
Returns `{:ok, new_state}` or `{:error, reason}`.

# `restartable?`

```elixir
@callback restartable?(state :: t()) :: boolean()
```

Whether the transport supports restart (e.g. re-spawning the binary).

Only `:spawn` mode supports this. Stdio and iostream transports
cannot be restarted because they don't own the renderer lifecycle.

# `send_data`

```elixir
@callback send_data(state :: t(), data :: iodata()) :: {:ok, t()} | {:error, term()}
```

Send iodata to the renderer. Returns `{:ok, state}` on success.

# `transport_ready?`

```elixir
@callback transport_ready?(state :: t()) :: boolean()
```

Whether the transport is ready to accept outgoing data.

---

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