# `Rexsilient.Options`
[🔗](https://github.com/fabiobarkoski/rexsilient/blob/v1.0.0/lib/rexsilient/options.ex#L1)

Validates the options given to strategies and recover modules.

The built-in modules use it in their `init/1`, and custom ones can too, so
that invalid options fail the same way: with an `ArgumentError` that
Rexsilient raises again with the declaration's name.

    @impl true
    def init(opts) do
      Rexsilient.Options.validate!(opts, delay: :non_neg_integer, budget: :pos_integer)
    end

# `type`

```elixir
@type type() :: :pos_integer | :non_neg_integer
```

The type an option must have:

  * `:pos_integer` - an integer greater than `0`.

  * `:non_neg_integer` - an integer greater than or equal to `0`.

# `validate!`

```elixir
@spec validate!(opts :: term(), spec :: [{atom(), type()}]) :: %{
  required(atom()) =&gt; term()
}
```

Validates `opts` against `spec`, a keyword list of `key: type`.

Every key in `spec` is required, and keys not in `spec` are rejected.
Returns the options as a map. Raises `ArgumentError` otherwise.

## Examples

    Rexsilient.Options.validate!([threshold: 5], threshold: :pos_integer)
    #=> %{threshold: 5}

    Rexsilient.Options.validate!([threshold: 0], threshold: :pos_integer)
    ** (ArgumentError) threshold must be a positive integer, got: 0

---

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