View Source Inspect.Opts (Elixir v1.11.1)
Defines the options used by the Inspect
protocol.
The following fields are available:
:base
- prints integers as:binary
,:octal
,:decimal
, or:hex
, defaults to:decimal
. When inspecting binaries any:base
other than:decimal
impliesbinaries: :as_binaries
.:binaries
- when:as_binaries
all binaries will be printed in bit syntax.When
:as_strings
all binaries will be printed as strings, non-printable bytes will be escaped.When the default
:infer
, the binary will be printed as a string if it is printable, otherwise in bit syntax. SeeString.printable?/1
to learn when a string is printable.:charlists
- when:as_charlists
all lists will be printed as charlists, non-printable elements will be escaped.When
:as_lists
all lists will be printed as lists.When the default
:infer
, the list will be printed as a charlist if it is printable, otherwise as list. SeeList.ascii_printable?/1
to learn when a charlist is printable.:custom_options
(since v1.9.0) - a keyword list storing custom user-defined options. Useful when implementing theInspect
protocol for nested structs to pass the custom options through.:inspect_fun
(since v1.9.0) - a function to build algebra documents. Defaults toInspect.inspect/2
.:limit
- limits the number of items that are inspected for tuples, bitstrings, maps, lists and any other collection of items, with the exception of printable strings and printable charlists which use the:printable_limit
option. If you don't want to limit the number of items to a particular number, use:infinity
. It accepts a positive integer or:infinity
. Defaults to50
.:pretty
- if set totrue
enables pretty printing. Defaults tofalse
.:printable_limit
- limits the number of characters that are inspected on printable strings and printable charlists. You can useString.printable?/1
andList.ascii_printable?/1
to check if a given string or charlist is printable. If you don't want to limit the number of characters to a particular number, use:infinity
. It accepts a positive integer or:infinity
. Defaults to4096
.:safe
- whenfalse
, failures while inspecting structs will be raised as errors instead of being wrapped in theInspect.Error
exception. This is useful when debugging failures and crashes for custom inspect implementations.:structs
- whenfalse
, structs are not formatted by the inspect protocol, they are instead printed as maps. Defaults totrue
.:syntax_colors
- when set to a keyword list of colors the output is colorized. The keys are types and the values are the colors to use for each type (for example,[number: :red, atom: :blue]
). Types can include:atom
,:binary
,:boolean
,:list
,:map
,:number
,:regex
,:string
, and:tuple
. Custom data types may provide their own options. Colors can be anyIO.ANSI.ansidata/0
as accepted byIO.ANSI.format/1
.:width
- number of characters per line used when pretty istrue
or when printing to IO devices. Set to0
to force each item to be printed on its own line. If you don't want to limit the number of items to a particular number, use:infinity
. Defaults to80
.
Link to this section Summary
Link to this section Types
@type color_key() :: atom()
@type t() :: %Inspect.Opts{ base: :decimal | :binary | :hex | :octal, binaries: :infer | :as_binaries | :as_strings, char_lists: :infer | :as_lists | :as_char_lists, 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 }