# `LibTmux.Ref`
[🔗](https://github.com/libtmux/libtmux-elixir/blob/86ad4ca80f157adb0c11f6bf7c371b04ca5aa688/lib/libtmux/ref.ex#L1)

An exact observed target bound to one server instance.

A window-link ID is its observed `{session_id, index, window_id}` binding,
not a unique lifetime identifier. Validation detects known stale instances;
it does not reserve an object or close a one-shot check/use race.

# `entity`

```elixir
@type entity() :: :session | :window | :pane | :window_link | :client
```

The target kind; physical windows and session-relative links have different identities.

# `id`

```elixir
@type id() :: String.t() | {String.t(), non_neg_integer(), String.t()}
```

A native ID or observed session/index/window link binding; neither reserves an object's lifetime.

# `t`

```elixir
@type t() :: %LibTmux.Ref{entity: entity(), id: id(), server_instance: String.t()}
```

An exact observed identity bound to a tmux server incarnation, separate from a connection epoch.

# `from_observation`

```elixir
@spec from_observation(LibTmux.Schema.observation()) ::
  {:ok, t()} | {:error, LibTmux.Error.t()}
```

Builds a reference from an observation's own identity and server instance.

Validates the identity with `new/3` without I/O or a fresh observation.
Malformed identities and other inputs return an `:invalid_target` error.
Other captured fields may remain unloaded or unavailable. A reference does
not prove that its target still exists. Window links retain their tuple
binding and lifetime limitation; domain actions reject window-link refs.

## Examples

    iex> pane = %LibTmux.Pane{id: "%7", server_instance: "instance-a"}
    iex> {:ok, ref} = LibTmux.Ref.from_observation(pane)
    iex> {ref.entity, ref.id, ref.server_instance}
    {:pane, "%7", "instance-a"}

# `new`

```elixir
@spec new(entity(), id(), String.t()) :: {:ok, t()} | {:error, LibTmux.Error.t()}
```

Validates a native identity and binds it to a nonempty instance token.

See the [worked example](api-examples.html#encoding-and-protocol).

# `validate`

```elixir
@spec validate(t(), String.t()) :: :ok | {:error, LibTmux.Error.t()}
```

Rejects malformed references and known server-instance mismatches.

See the [worked example](api-examples.html#encoding-and-protocol).

---

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