Inspect.Opts — Elixir v1.18.3 (original) (raw)

Defines the options used by the Inspect protocol.

The following fields are available:

Summary

Functions

Returns the default inspect function.

Sets the default inspect function.

Types

@type color_key() :: atom()

@type t() :: %Inspect.Opts{ base: :decimal | :binary | :hex | :octal, binaries: :infer | :as_binaries | :as_strings, char_lists: term(), charlists: :infer | :as_lists | :as_charlists, custom_options: keyword(), inspect_fun: (any(), t() -> Inspect.Algebra.t()), limit: non_neg_integer() | :infinity, pretty: boolean(), printable_limit: non_neg_integer() | :infinity, safe: boolean(), structs: boolean(), syntax_colors: [{color_key(), IO.ANSI.ansidata()}], width: non_neg_integer() | :infinity }

Functions

Returns the default inspect function.

Sets the default inspect function.

Set this option with care as it will change how all values in the system are inspected. The main use of this functionality is to provide an entry point to filter inspected values, in order for entities to comply with rules and legislations on data security and data privacy.

It is extremely discouraged for libraries to set their own function as this must be controlled by applications. Libraries should instead define their own structs with custom inspect implementations. If a library must change the default inspect function, then it is best to ask users of your library to explicitly call default_inspect_fun/1 with your function of choice.

The default is Inspect.inspect/2.

Examples

previous_fun = Inspect.Opts.default_inspect_fun()

Inspect.Opts.default_inspect_fun(fn
  %{address: _} = map, opts ->
    previous_fun.(%{map | address: "[REDACTED]"}, opts)

  value, opts ->
    previous_fun.(value, opts)
end)

Builds an Inspect.Opts struct.