# `GuardedStruct.Validate`
[🔗](https://github.com/mishka-group/guarded_struct/blob/v0.1.4/lib/guarded_struct/validate.ex#L1)

Standalone validators that reuse a `GuardedStruct` schema without going
through the full `builder/1` pipeline.

Three tiers:

  * `run/2` — derive op-string against a single value, no module needed.
  * `field/3,4` — validate one named field of a `guardedstruct` module.
    Cross-field dependencies (`on:`, `domain:`) honoured by mode.
  * `partial/2` — validate a subset of fields together. Missing fields
    skipped (no `enforce_keys` check). Useful for form-as-you-type and
    PATCH-style endpoints.

Returns the validated value (or partial map) on success, an error list
with the same shape as `builder/1` on failure.

# `error`

```elixir
@type error() :: %{
  :field =&gt; atom(),
  :action =&gt; atom(),
  :message =&gt; String.t(),
  optional(any()) =&gt; any()
}
```

# `field`

```elixir
@spec field(module(), atom(), any(), keyword()) :: {:ok, any()} | {:error, [error()]}
```

Validate a single named field of a `guardedstruct` module.

## Modes

  * `:strict` (default) — honour `on:` and `domain:` core keys. Errors if
    a cross-field dependency can't be resolved.
  * `:isolated` — skip cross-field deps. Run only `derive:` + `validator:`.

## Context

Pass `context: %{other_field: ...}` to provide values for cross-field
dependency resolution.

# `partial`

```elixir
@spec partial(module(), map()) :: {:ok, map()} | {:error, [error()]}
```

Validate a partial map of fields. Missing fields are skipped (no
`enforce_keys` check). Cross-field deps resolve from the same input.

# `run`

```elixir
@spec run(String.t(), any()) :: {:ok, any()} | {:error, [error()]}
```

Validate a value against a derive op-string. No module needed.

    iex> GuardedStruct.Validate.run("validate(string, max_len=80)", "hi")
    {:ok, "hi"}

The string is checked the way a `derives:` string is when a module compiles.
One that cannot be read, or whose operand is wrong, returns an error with the
action `:bad_parameters` and the field `:__value__`.

    iex> {:error, [%{action: :bad_parameters}]} =
    ...>   GuardedStruct.Validate.run("validate(max_len=foo)", "x")

---

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